python project import and export dependency packages

1. Export all dependent packages

Enter the project path and execute the following command:

pip freeze > requirements.txt

Then you can see the generated "requirements.txt" file in the current directory. You can open it and take a look. You will find that there is a lot of package information. In fact, here is the relevant information of all packages in your current python environment. If we only need to export the dependency packages required by the current project, I can use another approach.

2. Export only the dependency packages of the project

pipreqs ./

By default, the "pipregs" plug-in is not installed, so the following error will be prompted:
Insert image description here
Therefore, install it through the following command:

pip install pipreqs

Insert image description here
Then execute it pipreqs ./and you can export it.
If you already have it requirements.txtand need to use it pipreqs --force ./, you can export it successfully after a while.
Insert image description here
You can open the requirements.txt file to view the dependencies.

3. Import dependency packages

pip install -r requirements.txt

Guess you like

Origin blog.csdn.net/heromps/article/details/131498309