How to create requirements.txt python
A Virtual environment is an isolated workspace which keeps your packages separate from your local(main) system installation.
We generate and share requirements.txt files to make it easier for other developers to install the correct versions of the required Python libraries to run the Python code we’ve written.
pip freeze command can be used to output installed packages in requirements format. Packages are listed in a case-insensitive sorted order.
Steps to create requirements.txt
- Generate output suitable for a requirements file.
C:\> py -m pip freeze aniso8601==8.1.0 appdirs==1.4.4 asgiref==3.2.10 astroid==2.4.2 attrs==20.3.0 Automat==20.2.0 beautifulsoup4==4.9.3 certifi==2020.6.20 cffi==1.14.0 chardet==3.0.4 ...
py -m pip freeze : This command will output all the packages that are installed in the respective directory or virtual environment
2. To generate a requirements file and then install from it in another environment.
pip freeze > requirements.txt pip install -r requirements.txt