How to create and install Conda requirements.txt

Conda is an open-source package and environmentCollection of tools and packages for software development management system. It can easily install, uninstall, update, and manage packages in a virtual environment using simple commands. With the help of Conda, developing teams can share their development environments with one another using the requirements.txt file.

What is the need for the requirements.txt file?

Why do we need to share the environment? For that, let's take a look at a possible real-world scenario. Consider that we are working on a project along with our team. Our task is to build the back end of the web application using Python's Django framework. We use Conda as our package and environment manager to create an environment in which we install Python 3.10.1 and Django 4.2.3. After a month of hard work and testing, we have finally completed the back end and pushed the code on GitHub. Our team pulls the code in their local systems and tries to run it, but the code does not work on their local systems.

Dependencies issue

The reason was that the Python and Django versions the team installed on their systems were not the same as the version in which we were writing the code, and thus dependencies issues emerged.

In this case, we need to share the exact packages and dependencies we used in our system with our team. In this Answer, we will explore how we can create the requirements.txt file to store the dependencies and install them.

Create the requirements.txt file

Note: Before creating the requirements.txt file, we need to ensure we have activated our Conda environment.

To store all of the packages and dependencies installed in our environment, we can run the following command.

conda list -e > requirements.txt
Command to create the requirements.txt file

After running this command, the requirements.txt file will be created in the directory we are currently in. The structure of the requirements.txt file is given below.

technology1 == version
technology2 == version
technology3 == version
technology4 == version
...
Structure of requirements.txt file

For the scenario discussed above, running the command will create a requirements.txt file with the following dependencies.

Django == 4.2.3
python == 3.10.1
Example requirements.txt file

Install the requirements.txt file

Once the requirements.txt file is created, we can share it with our team or another environment and install the dependencies. For that, we can run the following command.

conda install --file requirements.txt
Command to install dependencies

On running the command, the dependencies will install in the system, and we are ready for coding.

Conclusion

Creating the requirements.txt file is important for code collaboration and sharing among different systems and environments.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved