Python 手动删除pip包后如何删除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21306954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove pip package after deleting it manually
提问by user3030969
I deleted a pip package with rm -rfcommand thinking that the package will be removed. Now the package has been deleted but it still shows up in pip listand I'm unable to remove it with pip uninstallnor can I update with pip install --upgrade.
我用rm -rf命令删除了一个 pip 包,认为该包将被删除。现在该软件包已被删除,但它仍然显示在其中pip list,我无法删除它,pip uninstall也无法使用pip install --upgrade.
I'd like to remove it completely. Can anyone please tell me how?
我想彻底删除它。谁能告诉我怎么做?
EDIT
编辑
The package is psycopg2.
软件包是 psycopg2。
If I try to uninstall :
如果我尝试卸载:
hammad@hammad-P5QL-E:~$ pip uninstall psycopg2
Can't uninstall 'psycopg2'. No files were found to uninstall.
This is the directory in which psycopg2 was located /usr/lib/python2.7/dist-packagesand I rm -rf'd it from the same directory.
这是 psycopg2 所在的目录,/usr/lib/python2.7/dist-packages我rm -rf从同一个目录中找到它。
TIA
TIA
采纳答案by Ashoka Lella
packages installed using pip can be uninstalled completely using
使用 pip 安装的软件包可以完全卸载使用
pip uninstall <package>
pip uninstallis likely to fail if the package is installed using python setup.py installas they do not leave behind metadata to determine what files were installed.
pip uninstall如果使用安装包,则可能会失败,python setup.py install因为它们不会留下元数据来确定安装了哪些文件。
packages still show up in pip listif their paths(.pth file) still exist in your site-packages or dist-packages folder. You'll need to remove them as well in case you're removing using rm -rf
pip list如果它们的路径(.pth 文件)仍然存在于您的 site-packages 或 dist-packages 文件夹中,则包仍会显示。如果您要删除使用,您还需要删除它们rm -rf
回答by Alfe
I'm sure there's a better way to achieve this and I would like to read about it, but a workaround I can think of is this:
我确信有更好的方法来实现这一点,我想阅读它,但我能想到的解决方法是:
- Install the package on a different machine.
- Copy the
rm'ed directory to the original machine (ssh, ftp, whatever). pip uninstallthe package (should work again then).
- 在不同的机器上安装包。
- 将
rm'ed 目录复制到原始机器(ssh、ftp 等)。 pip uninstall包(然后应该再次工作)。
But, yes, I'd also love to hear about a decent solution for this situation.
但是,是的,我也很想听听针对这种情况的体面解决方案。
回答by seddonym
- Go to the
site-packagesdirectory where pip is installing your packages. - You should see the egg file that corresponds to the package you want to uninstall. Delete the egg file (or, to be on the safe side, move it to a different directory).
- Do the same with the package files for the package you want to delete (in this case, the
psycopg2directory). pip install YOUR-PACKAGE
- 转到
site-packagespip 安装包的目录。 - 您应该会看到与要卸载的软件包对应的 egg 文件。删除 egg 文件(或者,为了安全起见,将其移动到不同的目录)。
- 对要删除的包(在本例中为
psycopg2目录)的包文件执行相同操作。 pip install YOUR-PACKAGE
回答by The Godfather
I met the same issue while experimenting with my own Python library and what I've found out is that pip freezewill show you the library as installed if your current directorycontains lib.egg-infofolder. And pip uninstall <lib>will give you the same error message.
我在试验我自己的 Python 库时遇到了同样的问题,我发现pip freeze如果您的当前目录包含lib.egg-info文件夹,它将向您显示已安装的库。并且pip uninstall <lib>会给你同样的错误信息。
- Make sure your current directory doesn't have any
egg-infofolders - Check
pip show <lib-name>to see the details about the location of the library, so you can remove files manually.
- 确保您的当前目录没有任何
egg-info文件夹 - 检查
pip show <lib-name>以查看有关库位置的详细信息,以便您可以手动删除文件。

