我正在尝试修复我的一个virtualenv -我想将所有已安装的库重置为与生产相匹配的库。
有没有一种快速简单的方法来处理皮普?
我正在尝试修复我的一个virtualenv -我想将所有已安装的库重置为与生产相匹配的库。
有没有一种快速简单的方法来处理皮普?
当前回答
pip3 freeze --local | xargs pip3 uninstall -y
情况可能是必须多次运行此命令才能获得空pip3 freeze—local。
其他回答
仅使用pip的跨平台支持:
#!/usr/bin/env python
from sys import stderr
from pip.commands.uninstall import UninstallCommand
from pip import get_installed_distributions
pip_uninstall = UninstallCommand()
options, args = pip_uninstall.parse_args([
package.project_name
for package in
get_installed_distributions()
if not package.location.endswith('dist-packages')
])
options.yes = True # Don't confirm before uninstall
# set `options.require_venv` to True for virtualenv restriction
try:
print pip_uninstall.run(options, args)
except OSError as e:
if e.errno != 13:
raise e
print >> stderr, "You lack permissions to uninstall this package.
Perhaps run with sudo? Exiting."
exit(13)
# Plenty of other exceptions can be thrown, e.g.: `InstallationError`
# handle them if you want to.
这适用于最新版本。我认为这是最简洁明了的表达方式。
virtualenv --clear MYENV
但是为什么不直接删除并重新创建virtualenv呢?
不变性规则。此外,很难记住所有的管道和其他解决方案使用。
对于Windows用户,这是我在Windows PowerShell上使用的
pip uninstall -y (pip freeze)
如果你正在运行virtualenv:
virtualenv --clear </path/to/your/virtualenv>
例如,如果virtualenv是/Users/you/。Virtualenvs /projectx,然后运行:
virtualenv --clear /Users/you/.virtualenvs/projectx
如果你不知道你的虚拟环境的位置,你可以在激活的虚拟环境中运行python来获取路径
在Windows上,如果你的路径配置正确,你可以使用:
pip freeze > unins && pip uninstall -y -r unins && del unins