In Python project development, each project is independent, so virtual environments are used , but the dependent packages and versions of each project are different.
For example: you need to take over a project that someone else has handed over to you, or you want to run a project written by yourself before, but the environment needs to be reconfigured, the dependencies must be downloaded again, and the version cannot be remembered. What should I do?
In fact, two pip commands can solve this problem well.
2. import dependencies
2.1 When we pull down a project on github , we can find that there is a
requirements.txtfolder in it, which contains various dependencies of the project
requirements.txt, there are all dependent packages and versions
2.3 Just enter the following commands in the terminal to install
requirements.txtthe dependencies required by the project
pip install -r requirements.txt
3. export dependency
3.1 As we all know,
pip listyou can view the dependencies of the current project installation, but its format is not
Dependency Packages == Versions
pip freezecan be used to print Dependency Packages == Versions
3.3 Then enter the following command in the terminal to export the above content and package it
requirements.txt and in
pip freeze >requirements.txt
3.4 When you need to use it later,
pip install -r requirements.txt you can directly use the command to install the dependencies with one click
This article is reprinted from: https://www.cnblogs.com/xuexianqi/p/13329692.html