Python-generate requirement.txt file

Preface##

How to generate requirements.txt

Enter the project root directory and execute the following command

pip3 freeze > requirements.txt

This will report a warning

**Means: **It is best to call pip through python, so it is recommended to type the following command to generate

python.exe -m pip freeze > requirements.txt

Use requirement.txt to install third-party libraries##

pip3 install -r requirement.txt

Things to pay attention to when using Pycharm##

Foreword###

Here comes the problem###

In this way, there will be a lot of third-party libraries that depend on the environment, but when the third-party libraries of a certain project do not need a lot, if you use this interpreter to generate requirement.txt at this time, there will be a lot of irrelevant libraries

how to solve this problem###

Assign a separate project interceptor to this project

Then click + to add an interpreter

The default is OK, click OK

python.exe

Generate requirement.txt

Use python.exe under venv/Scripts to generate requirement.txt

You're done, now the requirement.txt only contains the third-party libraries needed for this project!

Recommended Posts

Python-generate requirement.txt file