我正在尝试修复我的一个virtualenv -我想将所有已安装的库重置为与生产相匹配的库。
有没有一种快速简单的方法来处理皮普?
我正在尝试修复我的一个virtualenv -我想将所有已安装的库重置为与生产相匹配的库。
有没有一种快速简单的方法来处理皮普?
当前回答
为什么不直接用rm -r。venv重新开始呢?
其他回答
仅使用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.
如果你正在使用pew,你可以使用wipeenv命令:
皮尤wipeenv[环境]
我知道这是一个老问题,但我确实偶然发现了它,所以作为将来的参考,你现在可以这样做:
pip uninstall [options] <package> ...
pip uninstall [options] -r <requirements file> ...
-r,——需求文件 卸载给定需求文件中列出的所有包。此选项可多次使用。
来自PIP文档8.1版
使用pip list或pip freeze的其他答案必须包括——local,否则它还将卸载在公共名称空间中找到的包。
下面是我经常使用的代码片段
pip freeze --local | xargs pip uninstall -y
参考:pip freeze——救命
方法一(冷冻)
pip freeze | xargs pip uninstall -y
方法二(附pip表)
pip list | awk '{print $1}' | xargs pip uninstall -y
方法三(使用virtualenv)
virtualenv --clear MYENV