Using PIP freeze
$ pip freeze > requirements.txt
This approach is to list the entire package in the environment, if it is a virtual environment that can be used.
Normally we only need to export the requirements.txt of the current project, so we recommend Pipreqs.
Using Pipreqs
This tool is a good helper, can be scanned by the project directory, automatically discover the use of those class libraries, automatically generate a dependency list, only build project-related dependencies to Requirements.txt
Installation
pip install pipreqs
Use
Very simple to use PIPREQS path name
This goes directly to the project root, so yes./
pipreqs ./
Error
File "c:\users\devtao\appdata\local\programs\python\python36-32\lib\site-packages\pipreqs\pipreqs.py", line 341, in init extra_ignore_dirs=extra_ignore_dirs) File "c:\users\devtao\appdata\local\programs\python\python36-32\lib\site-packages\pipreqs\pipreqs.py", line 75, in get_all_imports contents = f.read()UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa6 in position 186: illegal multibyte sequence
If there is an error similar to the top unicodedecodeerror: ' GBK ' codec can ' t decode byte 0xa6 in position 186:illegal multibyte sequence
Modify the pipreqs.py 75 line directly and change the encoding to Utf-8
The Python project automatically generates the requirements file for the current project