> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# How to create your requirements.txt file

> Complete guide to the requirements.txt file in Python: learn how to create, list dependencies with pip freeze, pin versions, and prepare your project for production.

# 📋 requirements.txt file for Python

The `requirements.txt` file is the industry standard for specifying and managing dependencies in Python projects. This guide shows how to create, configure and use `requirements.txt` to ensure consistency between development and production environments.

## What is a requirements.txt file?

A `requirements.txt` file lists all external Python packages your project needs, with their specific versions. This allows:

* You and your team to maintain identical environments
* New collaborators to reproduce the environment exactly
* Deploy on Square Cloud to work with the correct dependencies

***

<Steps>
  <Step title="Activate the virtual environment">
    Working inside a virtual environment is essential to keep your project dependencies isolated from the global Python system. This avoids version conflicts and ensures reproducibility.

    Activate your virtual environment with one of the commands below, depending on your system:

    **Windows:**

    ```bash theme={null}
    venv\Scripts\activate
    ```

    **macOS/Linux:**

    ```bash theme={null}
    source venv/bin/activate
    ```
  </Step>

  <Step title="List project dependencies">
    <Warning>
      Always specify exact versions with `==` to ensure reproducibility and prevent breakage from incompatible updates in production.
    </Warning>

    ### Option A: Create manually (Recommended)

    Create a `requirements.txt` file in the root of your project and list all external packages with their versions:

    ```plaintext requirements.txt theme={null}
    discord.py==2.3.0
    requests==2.31.0
    python-dotenv==1.0.0
    ```

    ### Option B: Generate automatically with pip freeze

    After installing dependencies in your virtual environment, you can automatically generate the file. There are two main ways:

    **Option B1: Use `pip freeze` (includes everything)**

    ```bash theme={null}
    pip freeze > requirements.txt
    ```

    <Warning>
      Caution: `pip freeze` includes all globally installed packages, which may include unnecessary packages for your project. Review the file after generating and remove dependencies that are not strictly necessary.
    </Warning>

    **Option B2: Use `pipdeptree` or `pip freeze` with filtering (Recommended)**

    To capture ONLY your project's dependencies (without auxiliary environment packages), use:

    ```bash theme={null}
    pip freeze --user > requirements.txt
    ```

    Or, for a cleaner solution, install `pipdeptree`:

    ```bash theme={null}
    pip install pipdeptree
    pipdeptree -p your_project > requirements.txt
    ```

    Alternative: Use a manual list check or check which package was installed specifically for your project:

    ```bash theme={null}
    pip list | grep -i "your-package"
    ```

    <Note>
      If you are working in a virtual environment (recommended), `pip freeze` will work perfectly as the environment will be isolated and contain only your project's dependencies.
    </Note>
  </Step>

  <Step title="Review and validate dependencies">
    Open the `requirements.txt` file in your text editor and:

    1. Review the package list
    2. Remove unnecessary dependencies
    3. Update versions as needed
    4. Ensure you are using exact versions (with `==`)
  </Step>

  <Step title="Install dependencies">
    To install all listed dependencies:

    ```bash theme={null}
    pip install -r requirements.txt
    ```

    This command guarantees that all collaborators and production environments use exactly the same versions.
  </Step>

  <Step title="Version and share">
    With `requirements.txt` ready, you can:

    * Share it with your team
    * Put it in version control (git)
    * Ensure everyone works with the same versions
    * Simplify deployment on Square Cloud

    When you host your project on Square Cloud, the `requirements.txt` file is automatically detected and all dependencies are installed during build.
  </Step>
</Steps>

***

## 💡 Best Practices and Tips:

* **Keep updated**: Review and update `requirements.txt` regularly as you add new dependencies
* **Use exact versions**: Always use `==` instead of `>`, `>=` or no version to avoid surprises in production
* **Review pip freeze**: If using `pip freeze`, review the file before committing, as it may include unnecessary auxiliary packages
* **Versioning**: Commit `requirements.txt` to git to track dependency changes
* **Isolated environment**: Maintain one virtual environment per project to avoid global conflicts
* **Test locally**: Before deploying, test the file with `pip install -r requirements.txt` in a new environment

***

## 🚀 Next Steps

With your `requirements.txt` file configured:

1. Commit to your Git repository.
2. Host your project on **Square Cloud**.
3. Configure automatic deploy via GitHub.
4. Welcome to professional Python application hosting!

A well-structured `requirements.txt` file is the foundation for any successful Python application, ensuring your application works perfectly on Square Cloud.
