How does a Python project rebuild the runtime environment dependencies required by the project on another environment?

It is very troublesome to use side record, and there is always the problem of missing packages. At this time, manual installation is also very troublesome, and it is not sure what version of the package that needs to be installed for the code error. These problems can be solved by requirements.txt!

To generate requirements.txt, there are two ways:

The first applies to a single virtual environment:

pip freeze > requirements.txt
Copy the code

Why only a single virtual environment? Because of this, all dependencies in the environment will be added, and if you use the global environment, all downloaded packages will be included, regardless of the dependencies of the current project, as shown below

Of course, this is not what we want, but we can use the second method when we are working with a global environment.

Second (recommended) use pipreqs, github address: github.com/bndr/pipreq…

Pipreqs --encoding=utf8 --forceCopy the code

Encoding = utF8 UnicodeDecodeError: ‘GBK’ codec can’t decode byte 0xae in position 406: Error with illegal Multibyte sequence.

–force Overwrites requirements. TXT in the build directory if it exists.

Dang dang dang, you can see that’s all I rely on

Install dependencies using requirements.txt:

pip install -r requirements.txt
Copy the code