【问题标题】:'Permission denied' error when using pip install in virtualenv在 virtualenv 中使用 pip install 时出现“权限被拒绝”错误
【发布时间】:2015-08-19 18:50:42
【问题描述】:

编辑:已修复!

只需要 chown .cache 目录

我试过virtualenvwrapper docs 指令,我试过this guy's instructions 以及these...我试过sudo pip uninstall virtualenv , sudo pip uninstall virtualenvwrapper, sudo pip3 uninstall virtualenv, sudo pip3 uninstall virtualenvwrapper 在尝试每组指令之前。我看过其他 SO 帖子,如 this one,但 sudo 问题与我自己的不同。这样,我的意思是我在制作 virtualenv 时不使用 sudo,如果我尝试使用 sudo pip 安装包,它只会说我已经安装了包(在 virtualenv 之外)。

我也试过pip install --user virtualenv(wrapper)

这就是我所做的:

~ $ sudo pip3 install virtualenv
Downloading/unpacking virtualenv
  Downloading virtualenv-13.0.3-py2.py3-none-any.whl (1.7MB): 1.7MB downloaded
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
~ $ mkdir ~/.virtualenvs
~ $ sudo pip3 install virtualenvwrapper
Downloading/unpacking virtualenvwrapper
  Downloading virtualenvwrapper-4.5.1-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): virtualenv-clone in /usr/local/lib/python3.4/dist-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): stevedore in /usr/local/lib/python3.4/dist-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python3.4/dist-packages (from virtualenvwrapper)
Installing collected packages: virtualenvwrapper
Successfully installed virtualenvwrapper
Cleaning up...
~ $ export WORKON_HOME=~/.virtualenvs/

然后我将这两行添加到我的 .bashrc 中:(我还尝试将 VIRTUALENVWRAPPER_PYTHON 设置为 /usr/bin/python)

source /usr/local/bin/virtualenvwrapper.sh
VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3'

接下来我尝试了这个:

~ $ mkvirtualenv test
New python executable in test/bin/python
Installing setuptools, pip, wheel...done.
(test)~ $ pip install numpy
Collecting numpy
  Using cached numpy-1.9.2.tar.gz
Building wheels for collected packages: numpy
Exception:
Traceback (most recent call last):
  File "/home/aweeeezy/.virtualenvs/test/local/lib/python2.7/site-packages/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/home/aweeeezy/.virtualenvs/test/local/lib/python2.7/site-packages/pip/commands/install.py", line 291, in run
    wb.build(autobuilding=True)
  File "/home/aweeeezy/.virtualenvs/test/local/lib/python2.7/site-packages/pip/wheel.py", line 754, in build
    ensure_dir(output_dir)
  File "/home/aweeeezy/.virtualenvs/test/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 70, in ensure_dir
    os.makedirs(path)
  File "/home/aweeeezy/.virtualenvs/test/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/home/aweeeezy/.virtualenvs/test/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/home/aweeeezy/.virtualenvs/test/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/home/aweeeezy/.virtualenvs/test/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/home/aweeeezy/.cache/pip/wheels/4b'

为什么 virtualenv 不能正常工作?

【问题讨论】:

  • 看起来其中一个目录很时髦。不让你进去……
  • 确保在之前获取 venv,这样您就不会对原始环境有任何依赖。
  • @JosephSeungJaeDollar,喜欢source ~/.virtualenvs/test?这不起作用,因为 venv 是一个目录。编辑:你的意思是,source ~/virtualenvs/test/bin/activate,对吧? Thpat 仍然没有帮助。
  • 你以什么方式chown .cache 目录?你把新主人设给了谁?您是否更改了权限?
  • 这已在 pip 版本 7.1.1 (2015-08-20) pip.readthedocs.org/en/stable/news中修复

标签: python virtualenv virtualenvwrapper


【解决方案1】:

我认为如果你这样做 pip install numpy --no-cache-dir 会起作用的。

如果你运行pip --help,你会发现:

--no-cache-dir Disable the cache.

希望对以后的人有所帮助。

【讨论】:

  • 这 100% 今天帮助了我,以防有人遇到同样的问题。另一件事是我完全删除了虚拟环境并重新开始使用除了 --user 之外的这个命令。谢谢,弗拉迪尔!
  • 很好,它帮助了@TravisVOX。
【解决方案2】:

您需要更改 pip 目录的所有者。

运行chown -R <user>:<group> /home/aweeeezy/.cache/pip。

【讨论】:

  • 对于新手,chown -R $USER /home/aweeeezy/.cache/pip 也可以。
猜你喜欢
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-29
  • 1970-01-01
  • 1970-01-01
  • 2018-06-08
  • 2015-03-12
相关资源
最近更新 更多