Python automatically generates the requirements file for the current project

python automatically generates the requirements file for the current project

there are several ways:

1. Use PIP freeze

< pre style=”margin: 0px 0px 15px; padding: 0px; font-family: “Courier New” ! important; font-size: 12px ! important; The line – height: 1.72222; color: inherit; white-space: pre; border-radius: 6px; overflow-wrap: break-word;” > pip freeze > requirements.txt< /pre>

this way is to list the packages in the entire environment, if it is a virtual environment. In general, we only need to export the current project’s requirement.txt, and pipreqs

is recommended
2. Use pipreqs

is a helpful tool that scans the project directory to automatically discover which libraries are used, automatically generates dependency listings, and only generates project-related dependencies to requirements. TXT

installation

< pre style=”margin: 0px 0px 15px; padding: 0px; font-family: “Courier New” ! important; font-size: 12px ! important; The line – height: 1.72222; color: inherit; white-space: pre; border-radius: 6px; overflow-wrap: break-word;” > pip install pipreqs< /pre>

Use

also easy to use pipreqs pathname
here goes directly to the project root directory, so it is./
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

UnicodeDecodeError: ‘GBK’ codec can’t decode byte 0xa6 in position 186: illegal multibyte sequence
directly modify line 407 of pipreqs.py, change encoding to utf-8, save, and run on pipreqs./
pipreqs.py path

C:\Users\linxiao\AppData\Local\Programs\Python\Python37\Lib\site-packages\pipreqs



Read More: