问题:如何在全球而非本地安装pip软件包?

我正在尝试使用pip3安装flake8软件包,但似乎已拒绝安装,因为它已安装在一个本地位置。

如何强制它在全局(系统级别)安装?

pip3 install flake8
Requirement already satisfied (use --upgrade to upgrade): flake8 in ./.local/lib/python3.4/site-packages

请注意,我更喜欢一种通用解决方案(该解决方案应该在Debian,OS X甚至Windows上都可以使用),该解决方案可以在任何平台上使用,所以我不想自己指定目的地。

出于某种奇怪的原因,它的行为就像我已经指定了--user(在我的情况下我没有指定)。

我能够全局安装软件包的唯一方法是先将其删除,然后再重新安装。如果以某种方式存在,pip(8.1.1)似乎拒绝全局安装软件包。

免责声明:实验期间未使用或损坏任何虚拟环境。

I am trying to install flake8 package using pip3 and it seems that it refuses to install because is already installed in one local location.

How can I force it to install globally (system level)?

pip3 install flake8
Requirement already satisfied (use --upgrade to upgrade): flake8 in ./.local/lib/python3.4/site-packages

Please note that I would prefer a generic solution (that should work on Debian, OS X maybe even Windows), one that should be used on any platform so I don’t want to specify the destination myself.

For some weird reason it behaves like I already specified --user which in my case I didn’t.

The only way I was able to install a package globally was to first remove it and install it again after this. Somehow it seems that pip (8.1.1) refuses to install a package globally if it exists locally.

Disclaimer: No virtual environments were used or harmed during the experiments.


回答 0

您为什么不尝试sudo使用H标志?这应该可以解决问题。

sudo -H pip install flake8

普通人sudo pip install flake8将尝试使用您自己的主目录。该-H指示它使用系统的主目录。有关更多信息,访问https://stackoverflow.com/a/43623102/

Why don’t you try sudo with the H flag? This should do the trick.

sudo -H pip install flake8

A regular sudo pip install flake8 will try to use your own home directory. The -H instructs it to use the system’s home directory. More info at https://stackoverflow.com/a/43623102/


回答 1

也许--force-reinstall会奏效,否则就可以解决问题--ignore-installed

Maybe --force-reinstall would work, otherwise --ignore-installed should do the trick.


回答 2

您正在使用virtualenv吗?如果是,请禁用virtualenv。如果您不使用它,则它已经被广泛安装(系统级别)。尝试升级软件包。

pip install flake8 --upgrade

Are you using virtualenv? If yes, deactivate the virtualenv. If you are not using, it is already installed widely (system level). Try to upgrade package.

pip install flake8 --upgrade

回答 3

我实际上看不到您的问题。全局是python3路径的站点包文件夹中的任何包。

如果要仅在本地使用它,则必须配置virtualenv并在激活的虚拟环境中重新安装软件包。

I actually don‘t see your issue. Globally is any package which is in your python3 path‘s site package folder.

If you want to use it just locally then you must configure a virtualenv and reinstall the packages with an activated virtual environment.


回答 4

python中的pip安装在哪里进行?

我将提供我面临的Windows解决方案,并花了一些时间解决。

首先,在Windows中(如果使用Windows作为操作系统,则将Windows作为操作系统),pip install <package_name>默认情况下,它将全局安装(如果您尚未激活虚拟环境)。激活虚拟环境并进入虚拟环境后,所有pip安装都将在该虚拟环境内。


pip正在安装上述软件包,但是我不能使用它们吗?

对于这个pip,可能会警告您,pip可执行文件(例如pip3.exepip.exe不在您的path变量上。为此,您可以将此路径(通常为- C:\Users\<your_username>\AppData\Roaming\Programs\Python\)添加到环境变量中。重新启动后cmd,现在尝试使用已安装的python软件包。现在应该可以工作了。

Where does pip installations happen in python?

I will give a windows solution which I was facing and took a while to solve.

First of all, in windows (I will be taking Windows as the OS here), if you do pip install <package_name>, it will be by default installed globally (if you have not activated a virtual enviroment). Once you activate a virtual enviroment and you are inside it, all pip installations will be inside that virtual enviroment.


pip is installing the said packages but not I cannot use them?

For this pip might be giving you a warning that the pip executables like pip3.exe, pip.exe are not on your path variable. For this you might add this path ( usually – C:\Users\<your_username>\AppData\Roaming\Programs\Python\ ) to your enviromental variables. After this restart your cmd, and now try to use your installed python package. It should work now.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。