简体   繁体   English

如何冻结仅在虚拟环境中安装的包?

[英]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 freezepip 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.

相关问题 如何强制Jupyter Notebook仅使用虚拟环境中安装的软件包? - How to force a jupyter notebook to only use packages installed within a virtual environment? 如何访问安装在虚拟环境中的软件包? - How can I access packages installed in a virtual environment? 如何将已安装的软件包移动到新创建的虚拟环境中? - How to move installed packages to a newly created virtual environment ? Python虚拟环境未列出已安装的软件包 - Python virtual environment lists no installed packages 在虚拟环境中找不到 pip 安装的包 - pip installed packages not found in virtual environment 将虚拟环境安装的包导入 Jupyter Notebook - Importing Virtual Environment Installed Packages into Jupyter Notebook 如何仅使用 virtualenv 引导脚本在虚拟环境中安装 python 包? - How to install python packages in virtual environment only with virtualenv bootstrap script? 按照pip freeze 安装的模块在虚拟环境下无法导入 - Module installed according to pip freeze but unable to import in virtual environment 如何在所有已安装软件包都离线的情况下重新创建python虚拟环境? - How can I recreate a python virtual environment with all installed packages offline? 如何从 Python 虚拟环境中删除未使用的已安装包? - How do I remove unused installed packages from Python virtual environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM