我正在尝试修复我的一个virtualenv -我想将所有已安装的库重置为与生产相匹配的库。

有没有一种快速简单的方法来处理皮普?


当前回答

我做到了以下几点:

用当前安装的包列表创建名为reqs.txt的需求文件

pip freeze > reqs.txt

然后卸载reqs.txt中的所有包

# -y means remove the package without prompting for confirmation
pip uninstall -y -r reqs.txt

我喜欢这种方法,因为如果你犯了错误,你总是有一个pip需求文件可以依靠。它也是可重复的,而且是跨平台的(Windows、Linux、MacOs)。

其他回答

我只是想删除由项目安装的包,而不是我已经安装的其他包(比如neovim, mypy和pudb,我用于本地开发,但不包括在应用程序要求中)。于是我做了:

Cat requirements.txt| sed 's/=。*//g' | xargs PIP卸载-y

这对我来说很有效。

在Windows上,如果你的路径配置正确,你可以使用:

pip freeze > unins && pip uninstall -y -r unins && del unins
pip uninstall `pip freeze --user`

——user选项防止系统安装的包包含在清单中,从而避免/usr/lib和distutils权限错误。

我使用——user选项卸载安装在用户站点上的所有包。

pip3 freeze --user | xargs pip3 uninstall -y

Pip无法知道它安装了哪些包,系统的包管理器安装了哪些包。为此,您需要这样做

对于基于rpm的发行版(将python2.7替换为安装PIP的python版本):

find /usr/lib/python2.7/ |while read f; do
  if ! rpm -qf "$f" &> /dev/null; then
    echo "$f"
  fi
done |xargs rm -fr

对于基于deb的发行版:

find /usr/lib/python2.7/ |while read f; do
  if ! dpkg-query -S "$f" &> /dev/null; then
    echo "$f"
  fi
done |xargs rm -fr

然后清理剩下的空目录:

find /usr/lib/python2.7 -type d -empty |xargs rm -fr

我发现上面的答案非常误导人,因为它会从你的发行版中删除所有(大部分?)python包,可能会给你留下一个坏掉的系统。