> ## 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 a requirements.txt File

> Create a requirements.txt for a Python app: generate it with pip freeze inside a virtual environment, pin versions with ==, and deploy it on Square Cloud.

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="Create and activate a 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.

    Create the virtual environment in the root of your project (use `python3` if `python` is not found on macOS/Linux):

    ```bash theme={"system"}
    python -m venv .venv
    ```

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

    **Windows:**

    ```bash theme={"system"}
    .venv\Scripts\activate
    ```

    **macOS/Linux:**

    ```bash theme={"system"}
    source .venv/bin/activate
    ```

    Then install the packages your project uses, for example:

    ```bash theme={"system"}
    pip install discord.py python-dotenv
    ```
  </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: Generate with pip freeze (recommended)

    With the virtual environment activated, write every installed package and its exact version to the file:

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

    Inside a virtual environment, `pip freeze` lists only the packages installed in it (your dependencies and their sub-dependencies), already pinned with `==`.

    <Note>
      Outside a virtual environment, `pip freeze` lists every package installed on your system. Review the file and remove what your project does not use.
    </Note>

    ### Option B: Create manually

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

    ```plaintext requirements.txt theme={"system"}
    discord.py==2.7.1
    requests==2.34.2
    python-dotenv==1.2.3
    ```
  </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={"system"}
    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 its dependencies are installed with `pip install -r requirements.txt` before your app starts.
  </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 it to your Git repository.
2. Host your project with the [Python runtime guide](/en/articles/getting-started-with-python), or follow a framework guide: [Django](/en/tutorials/api/django), [Flask](/en/tutorials/api/flask) or [FastAPI](/en/tutorials/api/fastapi).
3. [Deploy automatically from GitHub](https://help.squarecloud.app/en-us/article/how-to-connect-your-github-repository-and-deploy-automatically-mr6srt/) on every push.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.