通过虚拟环境中的pip安装软件包:权限被拒绝

时间:2017-09-17 10:12:33

标签: python ubuntu permissions pip virtualenv

注意:我也在Ubuntu 桌面 16.04上执行了相同的步骤,但没有收到任何错误。

我在Ubuntu 服务器 16.04。

我已登录为" user1"谁有sudo特权。

我从源代码安装了Python 3.6.2:

$ sudo apt install build-essential checkinstall
$ sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
$ wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
$ tar xvf Python-3.6.2.tar.xz

$ cd Python-3.6.2/

$ ./configure --enable-shared --prefix=/usr/local LDFLAGS="-Wl,--rpath=/usr/local/lib"
$ sudo make altinstall

安装正确完成,但输出结束如下:

The directory '/home/user1/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/user1/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.1 setuptools-28.8.0

但我可以看到" user1"是" .cache"的所有者。文件夹:

~$ ls -la .cache/
drwx------ 3 user1 sudo 4096 Sep 17 12:41 pip

我创建了一个名为" test"的虚拟环境:

~/virtualenvs$ python3.6 -m venv test

激活它:

~/virtualenvs$ source test/bin/activate
(test) ~/virtualenvs$


(test) ~/virtualenvs$ which python
/home/user1/virtualenvs/test/bin/python
(test) ~/virtualenvs$ which pip
/home/user1/virtualenvs/test/bin/pip

当我尝试安装" mod_wsgi"包裹,我得到了#34;权限被拒绝"错误:

(test) ~/virtualenvs$ pip install mod_wsgi
Collecting mod_wsgi
  Using cached mod_wsgi-4.5.18.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info/mod_wsgi.egg-info
    writing pip-egg-info/mod_wsgi.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/mod_wsgi.egg-info/dependency_links.txt
    writing entry points to pip-egg-info/mod_wsgi.egg-info/entry_points.txt
    writing top-level names to pip-egg-info/mod_wsgi.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/mod_wsgi.egg-info/SOURCES.txt'
    /usr/local/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    warning: manifest_maker: standard file '-c' not found

    error: [Errno 13] Permission denied: '/usr/local/lib/python3.6/lib2to3/Grammar3.6.2.final.0.pickle'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-sp0fende/mod-wsgi/

如果我更改了以下权限:

$ sudo chmod -R 777 /usr/local/lib/python3.6/lib2to3/

这解决了这个问题,我可以安装该软件包。但如果可能的话,我宁愿使用另一种解决方案。

有没有人有想法?

修改

我通过更改以下2个文件的权限解决了这个问题:

$ sudo chmod 777 /usr/local/lib/python3.6/lib2to3/Grammar3.6.2.final.0.pickle
$ sudo chmod 777 /usr/local/lib/python3.6/lib2to3/PatternGrammar3.6.2.final.0.pickle

0 个答案:

没有答案