pip install产生OSError:[Errno 13]权限被拒绝:

时间:2016-04-15 17:23:13

标签: python-2.7 pip virtualenv ubuntu-16.04

我想通过virtualenv中的pip安装十个软件包。

我可能在我的匆忙中不正当地使用sudo来获得它"工作"正如https://stackoverflow.com/a/27939356/1063287所建议的那样,即我用sudo安装了virtualenv:

sudo virtualenv --no-site-packages ENV

我这样做是因为没有sudo我得到了这个:

me@my-comp:/var/www/html$ virtualenv --no-site-packages ENV
Running virtualenv with interpreter /usr/bin/python2
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2364, in <module>
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 942, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 1144, in install_python
    mkdir(lib_dir)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 324, in mkdir
    os.makedirs(path)
  File "/usr/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/usr/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/var/www/html/ENV'

Ubuntu 16.04我看不到&#34;磁盘工具&#34;然而,测试提供的解决方案。

尝试pip install lxml会导致最终错误:

Command "/var/www/html/ENV/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-jcCDbh/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-_oNugl-record/install-record.txt --single-version-externally-managed --compile --install-headers /var/www/html/ENV/include/site/python2.7/lxml" failed with error code 1 in /tmp/pip-build-jcCDbh/lxml/

虽然下面还有两个例子:

pip安装瓶:

(ENV) me@my-comp:/var/www/html/ENV$ pip install bottle
Collecting bottle
Installing collected packages: bottle
Exception:
Traceback (most recent call last):
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/commands/install.py", line 335, in run
    prefix=options.prefix_path,
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/req/req_set.py", line 732, in install
    **kwargs
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/req/req_install.py", line 835, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/req/req_install.py", line 1030, in move_wheel_files
    isolated=self.isolated,
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/wheel.py", line 344, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/wheel.py", line 322, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/var/www/html/ENV/lib/python2.7/site-packages/bottle.pyc'

pip安装请求:

(ENV) me@my-comp:/var/www/html/ENV$ pip install requests
Collecting requests
  Using cached requests-2.9.1-py2.py3-none-any.whl
Installing collected packages: requests
Exception:
Traceback (most recent call last):
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/commands/install.py", line 335, in run
    prefix=options.prefix_path,
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/req/req_set.py", line 732, in install
    **kwargs
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/req/req_install.py", line 835, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/req/req_install.py", line 1030, in move_wheel_files
    isolated=self.isolated,
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/wheel.py", line 344, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/wheel.py", line 315, in clobber
    ensure_dir(destdir)
  File "/var/www/html/ENV/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/var/www/html/ENV/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/var/www/html/ENV/lib/python2.7/site-packages/requests-2.9.1.dist-info'

如果我使用sudo pip install bottle,我会:

sudo: pip: command not found

更新

我提出了这个建议:

$sudo chown -R $(whoami) /var/www/html/ENV

现在可以点击安装bottlerequestspymongobeautifulsoup4Beakerpycryptotldextract。但是,lxmlpillow失败。

lxml失败:

Failed building wheel for lxml

Command "/var/www/html/ENV/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-yHLQQe/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-hLznuQ-record/install-record.txt --single-version-externally-managed --compile --install-headers /var/www/html/ENV/include/site/python2.7/lxml" failed with error code 1 in /tmp/pip-build-yHLQQe/lxml/

枕头失败:

Failed building wheel for pillow

Command "/var/www/html/ENV/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-IkuM34/pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-60McJh-record/install-record.txt --single-version-externally-managed --compile --install-headers /var/www/html/ENV/include/site/python2.7/pillow" failed with error code 1 in /tmp/pip-build-IkuM34/pillow/

我在这里尝试了这个建议:

https://stackoverflow.com/a/6504860/1063287

用于排除这些剩余错误,并且已安装libxml2-devlibxslt1-devpython2.7-dev

更新2:

按照以下方式安装zlib1g-dev

https://stackoverflow.com/a/19289133/1063287

现在可以安装lxml

仍然无法安装pillow

更新3:

按照以下方式安装libjpeg8-dev

https://stackoverflow.com/a/33582789/1063287

现在可以安装pillow

2 个答案:

答案 0 :(得分:1)

你安装了pip吗?

尝试按

安装pip
sudo apt-get install python

,从https://pip.pypa.io/en/stable/installing/下载点,然后执行&#39; python get-pip.py&#39;。这将安装pip

然后对于权限被拒绝使用的问题

$sudo chown -R $(whoami) /var/www/html/ENV

答案 1 :(得分:1)

解决方案是这个建议的组合:

$sudo chown -R $(whoami) /var/www/html/ENV

确保安装了以下软件包: