[英]How to freeze packages installed only in the virtual environment?
How to freeze packages installed only in the virtual environment, that is, without the global ones?如何冻结仅在虚拟环境中安装的包,即没有全局包?
You need to use the -l
or --local
option to freeze only the local packages (and not the global ones)您需要使用
-l
或--local
选项只冻结本地包(而不是全局包)
pip freeze -l > requirements.txt
Make sure you are working in the virtualenv
before doing pip freeze -l
.在执行
pip freeze -l
之前,请确保您在virtualenv
中工作。
Only local packages on virtual environment虚拟环境中只有本地包
pip freeze -l > requirements.txt # or --local instead of -l
Only local packages installed by the user on virtual environment仅由用户在虚拟环境中安装的本地软件包
pip freeze --user > requirements.txt
See the documentation for further details: https://pip.pypa.io/en/stable/reference/pip_freeze/ .有关更多详细信息,请参阅文档: https : //pip.pypa.io/en/stable/reference/pip_freeze/ 。
对我来说(macOS)以下工作
path/to/venv/bin/pip3 freeze -l
I'm on Windows 10, python 3.6, with my virtual environment called env activated using command prompt I found that pip freeze -l
does not work (error), python -m pip freeze -l
does not work (gets global packages) but changing into my virtual environment Scripts directory and running pip freeze
or pip freeze -l
works.我在 Windows 10,python 3.6 上,使用命令提示符激活了名为env 的虚拟环境我发现
pip freeze -l
不起作用(错误), python -m pip freeze -l
不起作用(获取全局包)但是进入我的虚拟环境 Scripts 目录并运行pip freeze
或pip freeze -l
工作。 Here is an example of this solution/work-around with my virtual environment, env :这是我的虚拟环境env的此解决方案/变通方法的示例:
cd \env\Scripts
pip freeze > ..\..\requirements.txt
python venv/Path_to/bin/pip freeze -l
I did try everything, even i inside venv it not worked.我确实尝试了所有方法,即使我在 venv 中也没有用。 This code worked for me.
这段代码对我有用。 It shows only pip packages in venv.
它在 venv 中仅显示 pip 个包。
venv\Scripts\python.exe venv\Scripts\pip.exe freeze > requirements.txt
Install whatever you need to freeze in your virtual environment, and then安装您需要在虚拟环境中冻结的任何内容,然后
pip freeze > requirements.txt
After that install the packages in the virtual environment that you do not want to freeze.之后,在您不想冻结的虚拟环境中安装软件包。
尝试以下命令:
pip -E /path/to/env/ freeze
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.