Python中pip freeze和pip list的区别
The difference between pip freeze and pip list in Python
pip freeze
和之间的区别pip list
在于:
pip freeze
以可用于生成requirements.txt
文件的需求格式输出用户安装的包。pip list
输出所有已安装的包,包括可编辑的。
pip freeze
用于生成requirements.txt
文件
您将最常使用该pip freeze
命令来生成
requirements.txt
文件。
pip freeze > requirements.txt pip3 freeze > requirements.txt
pip freeze
到一个名为. requirements.txt
requirements.txt文件可用于安装包和重新创建环境。
pip install -r requirements.txt pip3 install -r requirements.txt
requirements.txt
只能从
pip freeze命令的输出生成文件,而不能从pip list
.
pip
包的名称和特定版本由两个等号分隔,这是用于安装特定版本包的语法。
pip install requests==2.28.0 pip3 install requests==2.28.0
该pip list
命令以不同的格式输出包
pip list命令还显示已安装的包及其版本,但格式不同。
pip freeze
命令不输出 pip 默认依赖的包,例如wheel
和setuptools
,而pip list
命令输出。You can use the --all
option if you need to include the
pip,
setuptools, distrubute
and
wheel packages in the
output of pip freeze
.
pip freeze --all
The pip list
outputs all installed packages, including editables, whereas
pip freeze
shows the packages the user installed and their dependencies.
If you don’t use a virtual environment, it is recommended to create one as they
make management of packages much easier.
# 👇️ optionally store currently installed packages in a file pip freeze > requirements.txt pip3 freeze > requirements.txt # 👇️ use correct version of Python when creating VENV python -m venv venv # 👇️ activate on Unix or MacOS source venv/bin/activate # 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # 👇️ Upgrade pip pip install --upgrade pip # 👇️ install package in virtual environment pip install requests # 👇️ optionally install packages from a `requirements.txt` file pip install -r requirements.txt pip3 install -r requirements.txt
If the python -m venv venv
command doesn’t work, try one of the following
commands:
python3 -m venv venv
py -m venv venv
Make sure to use the correct activation command depending on your operating
system.
Note that the name requirements.txt
is just a convention. You can use any to
store the output of the pip freeze
command and you can have as many
requirements
files as necessary.
# Additional Resources
You can learn more about the related topics by checking out the following
tutorials:
- Pip install multiple requirements files in Python
- How to pip install a package Globally instead of Locally
- Pip install and uninstall in silent, non-interactive mode
- Pip install a specific version of a Python package
- Pip list all available versions of a Python package
- The purpose of pip’s
--no-cache-dir
option