简体   繁体   English

在本地安装 pip3 包

[英]Install pip3 package locally

Having used npm for some time, I'm struggling to understand why pip3 (ie: pip with Python 3) is so stubborn when it comes to manage permissions.使用 npm 一段时间后,我很难理解为什么 pip3(即:pip with Python 3)在管理权限方面如此顽固。

So far, I've been using pip3 with sudo as I'm the only one using this computer and I don't mind installing packages globally到目前为止,我一直在使用 pip3 和 sudo 因为我是唯一一个使用这台计算机的人,而且我不介意在全球范围内安装软件包

Today I wanted to install the pep8 package and use it locally without sudo.今天想安装pep8包,在本地使用,不用sudo。 pep8 can be used by IDEs and they would not be able to use it without sudo. pep8 可由 IDE 使用,如果没有 sudo,他们将无法使用它。 Therefore, I'd like to run因此,我想跑

pip3 install --user pep8

However, command doesn't work without sudo.但是,没有 sudo 命令将无法工作。 Console throws a traceback with a PermissionError:控制台抛出一个带有 PermissionError 的回溯:

PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.4/site-packages/pip/__init__.py'

And if run with sudo, quite logically, pep8 is installed in /root如果使用 sudo 运行,从逻辑上讲,pep8 安装在/root

With 2.7, the workaround is to uninstall pip and then reinstall it locally with --user.对于 2.7,解决方法是卸载 pip,然后使用 --user 在本地重新安装它。 At the moment, though, I'm unable to uninstall pip3.不过,目前我无法卸载 pip3。 At least in Fedora 22, dependencies seem to be quite tight.至少在 Fedora 22 中,依赖关系似乎非常紧密。 My guess is that pip3 comes bundled with 3.4 and that makes matters worse.我的猜测是 pip3 与 3.4 捆绑在一起,这让事情变得更糟。

And so, running所以,运行

python3 get-pip.py --user

gives a permission error because the script looks at current pip3 installations.给出权限错误,因为脚本查看当前的 pip3 安装。 If I run the command with sudo, the --user works (I believe it's still in testing mode?) but, logically, it installs it in the /root folder如果我使用 sudo 运行命令,则 --user 工作(我相信它仍处于测试模式?)但从逻辑上讲,它将它安装在/root文件夹中

In short, is there a way to use pip with Python3 to install packages locally?简而言之,有没有办法使用pip和Python3在本地安装包?

Within a console start your version of python you want to install the package for.在控制台中启动您要为其安装软件包的 Python 版本。 Run the python with the permission you want it to be installed with.使用您希望安装它的权限运行 python。 Python 3 and without sudo in this case.在这种情况下,Python 3 没有sudo

python3蟒蛇3

Thank in the python instance install the package you want.感谢在 python 实例中安装你想要的包。

import pip

#Ininstall the package
#This is the path to the setup and unzipped package. Path to the folder with setup.py.
path_to_setup = "/usr/lib/python3.4/site-packages/pep8"
#finelly runs the installation
pip.main (['install', path_to_setup])
#You will see some data processed.
#Now test it. In this case the package is pep8
import pep8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM