如何在全局而不是本地安装 pip 包? [英] How do I install a pip package globally instead of locally?

查看:40
本文介绍了如何在全局而不是本地安装 pip 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

请注意,我更喜欢通用解决方案(应该适用于 Debian、OS X 甚至 Windows),应该在任何平台上使用,所以我不想自己指定目标.

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.

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

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

我能够全局安装软件包的唯一方法是先将其删除,然后再重新安装.不知何故,pip (8.1.1) 似乎拒绝在本地安装一个包,如果它存在于本地.

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.

推荐答案

为什么不试试带有 H 标志的 sudo?这应该可以解决问题.

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

sudo -H pip install flake8

常规 sudo pip install flake8 将尝试使用您自己的主目录.-H 指示它使用系统的主目录.更多信息请访问 https://stackoverflow.com/a/43623102/

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/

这篇关于如何在全局而不是本地安装 pip 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆