问题:如何卸载使用pip install –user安装的软件包
--user
pip 有一个选项,可以为每个用户安装Python软件包:
pip install --user [python-package-name]
我使用此选项在没有root访问权限的服务器上安装软件包。我现在需要的是在当前用户上卸载已安装的软件包。我试图执行以下命令:
pip uninstall --user [python-package-name]
但是我得到了:
no such option: --user
pip install --user
除了手动查找和删除软件包外,如何卸载与之一起安装的软件包?
我发现这篇文章
pip无法从每个用户的站点软件包目录中卸载
描述了不支持从用户目录卸载软件包。根据文章,如果正确实施,则使用
pip uninstall [package-name]
安装的软件包也将在用户目录中搜索。但是对我来说仍然是一个问题。如果在系统范围和每个用户都安装了相同的软件包,该怎么办?如果有人需要针对特定用户目录怎么办?
There is a --user
option for pip which can install a Python package per user:
pip install --user [python-package-name]
I used this option to install a package on a server for which I do not have root access. What I need now is to uninstall the installed package on the current user. I tried to execute this command:
pip uninstall --user [python-package-name]
But I got:
no such option: --user
How can I uninstall a package that I installed with pip install --user
, other than manually finding and deleting the package?
I’ve found this article
pip cannot uninstall from per-user site-packages directory
which describes that uninstalling packages from user directory does not supported. According to the article if it was implemented correctly then with
pip uninstall [package-name]
the package that was installed will be also searched in user directories. But a problem still remains for me. What if the same package was installed both system-wide and per-user?
What if someone needs to target a specific user directory?
回答 0
在Linux上使用Python 3.5和pip 7.1.2测试了这一情况之后,情况似乎是这样的:
pip install --user somepackage
可以使用进行安装$HOME/.local
和卸载pip uninstall somepackage
。
无论是否somepackage
同时在全系统范围内安装,都是如此。
如果在两个地方都安装了该软件包,则只会卸载本地软件包。要使用卸载系统范围的软件包pip
,请先在本地将其卸载,然后使用root
特权再次运行相同的卸载命令。
除了预定义的用户安装目录外,pip install --target somedir somepackage
还将软件包安装到中somedir
。无法使用从这样的位置卸载软件包pip
。(但是在Github上实现了一个有点旧的未合并的pull请求,它实现了pip uninstall --target
。)
由于pip
将要卸载的唯一位置是系统范围的和预定义的本地用户,因此您需要以pip uninstall
相应用户身份运行才能从给定用户的本地安装目录中卸载。
Having tested this using Python 3.5 and pip 7.1.2 on Linux, the situation appears to be this:
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.
回答 1
在MacOS上卸载软件包’oauth2client’的示例:
pip uninstall oauth2client
example to uninstall package ‘oauth2client’ on MacOS:
pip uninstall oauth2client
回答 2
但是,对于pip install --user some_pkg
在虚拟环境中使用的人员要小心。
$ path/to/python -m venv ~/my_py_venv
$ source ~/my_py_venv/bin/activate
(my_py_venv) $ pip install --user some_pkg
(my_py_venv) $ pip uninstall some_pkg
WARNING: Skipping some_pkg as it is not installed.
(my_py_venv) $ pip list
# Even `pip list` will not properly list the `some_pkg` in this case
在这种情况下,您必须停用当前的虚拟环境,然后使用相应的python
/ pip
可执行文件列出或卸载用户站点软件包:
(my_py_venv) $ deactivate
$ path/to/python -m pip list
$ path/to/python -m pip uninstall some_pkg
请注意,此问题是几年前报告的。似乎当前的结论是:在虚拟环境中--user
无效pip
,因为用户位置对于虚拟环境而言实际上没有任何意义。
Be careful though, for those who using pip install --user some_pkg
inside a virtual environment.
$ path/to/python -m venv ~/my_py_venv
$ source ~/my_py_venv/bin/activate
(my_py_venv) $ pip install --user some_pkg
(my_py_venv) $ pip uninstall some_pkg
WARNING: Skipping some_pkg as it is not installed.
(my_py_venv) $ pip list
# Even `pip list` will not properly list the `some_pkg` in this case
In this case, you have to deactivate the current virtual environment, then use the corresponding python
/pip
executable to list or uninstall the user site packages:
(my_py_venv) $ deactivate
$ path/to/python -m pip list
$ path/to/python -m pip uninstall some_pkg
Note that this issue was reported few years ago. And it seems that the current conclusion is: --user
is not valid inside a virtual env’s pip
, since a user location doesn’t really make sense for a virtual environment.
回答 3
我认为可以卸载带有--user
flag的软件包。这个为我工作;
pip freeze --user | xargs pip uninstall -y
对于python 3;
pip3 freeze --user | xargs pip3 uninstall -y
但是以某种方式,这些命令不会卸载setuptools和pip。在这些命令之后(如果您确实想要干净的python),可以使用以下命令删除它们:
pip uninstall setuptools && pip uninstall pip
I think it’s possible to uninstall packages installed with --user
flag. This one worked for me;
pip freeze --user | xargs pip uninstall -y
For python 3;
pip3 freeze --user | xargs pip3 uninstall -y
But somehow these commands don’t uninstall setuptools and pip. After those commands (if you really want clean python) you may delete them with;
pip uninstall setuptools && pip uninstall pip
回答 4
The answer is Not possible yet. You have to remove it manually.
回答 5
正如@ thomas-lotze提到的那样,由于没有相应的–user选项,当前pip工具无法执行此操作。但是我发现我可以检入〜/ .local / bin并查找特定的pip#。#,在我看来它对应于–user选项。
就我而言:
antho@noctil: ~/.l/bin$ pwd
/home/antho/.local/bin
antho@noctil: ~/.l/bin$ ls pip*
pip pip2 pip2.7 pip3 pip3.5
然后只需卸载特定的pip版本即可。
As @thomas-lotze has mentioned, currently pip tooling does not do that as there is no corresponding –user option. But what I find is that I can check in ~/.local/bin and look for the specific pip#.# which looks to me like it corresponds to the –user option.
In my case:
antho@noctil: ~/.l/bin$ pwd
/home/antho/.local/bin
antho@noctil: ~/.l/bin$ ls pip*
pip pip2 pip2.7 pip3 pip3.5
And then just uninstall with the specific pip version.
回答 6
我正在运行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
>>>
加工!
I am running Anaconda version 4.3.22 and a python3.6.1 environment, and had this problem. Here’s the history and the fix:
pip uninstall opencv-python # -- the original step. failed.
ImportError: DLL load failed: The specified module could not be found.
I did this into my python3.6 environment and got this error.
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.
Next, I tried downloading python3.6 and putting the python3.dll in the folder and in various folders. nothing changed.
finally, this fixed it:
pip uninstall opencv-python
(the other conda-forge version is still installed) This left only the conda version, and that works in 3.6.
>>>import cv2
>>>
working!