简体   繁体   English

无法使用pip安装软件包

[英]unable to install package using pip

I am trying to install module using pip and I get this error: 我正在尝试使用pip安装模块,但出现此错误:

$ pip install virtualenv

Collecting virtualenv
  Downloading virtualenv-15.0.3-py2.py3-none-any.whl (3.5MB)
    100% |████████████████████████████████| 3.5MB 312kB/s
Installing collected packages: virtualenv
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 742, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/wheel.py", line 324, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/virtualenv.py'

What is the problem and how can I resolve it? 有什么问题,我该如何解决?

the problem is caused because you have not given the super user permission to the system. 引起此问题的原因是您尚未授予系统超级用户权限。 in order to make any changes into the system you should go to super user mode, for that you have to type the code as 为了对系统进行任何更改,您应该进入超级用户模式,因为您必须将代码键入为

sudo pip install virtualenv

it will help you out 它会帮助你

It's probably because the user you are logged as can't install to that folder. 可能是因为您登录的用户无法安装到该文件夹​​。

First option : You can do: 第一种选择 :您可以执行以下操作:

sudo pip install virtualenv

to download as root user 以root用户身份下载

Second Option : you could do these commands in sequence in terminal: 第二种选择 :您可以在终端中依次执行以下命令:

First: 第一:

cd /Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/

This command will go to the folder you have pip installed in. 该命令将转到您安装了pip的文件夹。

Second: 第二:

ls -l                                  

This command will show permissions for files/folders. 此命令将显示文件/文件夹的权限。 In on the of the columns you will see users who has access to folder pip (eg. root). 在各列的上,您将看到有权访问文件夹pip(例如root)的用户。

Third: Change it to the user you are logged in as with instead of root: 第三:将其更改为您以root身份登录的用户,而不是root用户:

sudo chown -R your_username:your_username path/to/pip/

This is assuming that folders up in the hierarchy don't have root permissions, otherwise you would need to change them too. 这是假设层次结构中的文件夹没有root权限,否则您也需要更改它们。 I'm talking about: Library, Python etc. 我说的是:库,Python等。

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

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