pip有一个——user选项,可以为每个用户安装Python包:
pip install --user [python-package-name]
我使用此选项在我没有根访问权限的服务器上安装包。我现在需要的是卸载当前用户上安装的包。我试图执行这个命令:
pip uninstall --user [python-package-name]
但我得到了:
no such option: --user
如何卸载我用pip install——user安装的包,而不是手动查找和删除包?
我找到了这篇文章
PIP无法从每个用户的site-packages目录卸载
说明不支持从用户目录卸载包。根据这篇文章,如果它被正确执行,那么
pip uninstall [package-name]
还将在用户目录中搜索已安装的包。但我仍然有一个问题。如果在系统范围内和每个用户都安装了相同的包呢?
如果有人需要针对特定的用户目录怎么办?
我强烈建议您使用虚拟环境进行python包安装。使用virtualenv,可以防止任何包冲突,并与python相关的用户域命令完全隔离。
要删除全局安装的所有包,请遵循以下命令;
可以卸载使用——user标志安装的包。这个方法对我很有效;
PIP冻结——用户| xargs PIP卸载-y
对于python 3;
Pip3冻结——用户| xargs Pip3卸载-y
但不知何故,这些命令不能卸载setuptools和pip。在这些命令之后(如果你真的想要干净的python),你可以用;
PIP卸载setuptools && PIP卸载PIP
现在你有了干净的python环境。您可以创建virtualenv并在其中安装包。
我正在运行Anaconda 4.3.22版本和python3.6.1环境,遇到了这个问题。以下是历史和解决方案:
pip uninstall opencv-python # -- the original step. failed.
ImportError: DLL load failed: The specified module could not be found.
我在python3.6环境中这样做了,得到了这个错误。
python -m pip install opencv-python # same package as above.
conda install -c conda-forge opencv # separate install parallel to opencv
pip-install opencv-contrib-python # suggested by another user here. doesn't resolve it.
接下来,我尝试下载python3.6,并将python3.dll放在该文件夹和其他文件夹中。没有什么改变。
最后,这就解决了问题:
pip uninstall opencv-python
(另一个conda-forge版本仍然安装)这只剩下conda版本,在3.6中工作。
>>>import cv2
>>>
工作!
在Linux上使用Python 3.5和pip 7.1.2进行测试后,情况似乎是这样的:
pip install --user somepackage installs to $HOME/.local, and uninstalling it does work using pip uninstall somepackage.
This is true whether or not somepackage is also installed system-wide at the same time.
If the package is installed at both places, only the local one will be uninstalled. To uninstall the package system-wide using pip, first uninstall it locally, then run the same uninstall command again, with root privileges.
In addition to the predefined user install directory, pip install --target somedir somepackage will install the package into somedir. There is no way to uninstall a package from such a place using pip. (But there is a somewhat old unmerged pull request on Github that implements pip uninstall --target.)
Since the only places pip will ever uninstall from are system-wide and predefined user-local, you need to run pip uninstall as the respective user to uninstall from a given user's local install directory.