“PermissionError:[Errno 13]权限被拒绝:'/ usr / lib / python3.5 / site-packages'”安装Django

时间:2016-10-10 01:37:08

标签: python django pip virtualenv django-1.10

我无法在Ubuntu上安装基本的Django软件包。我刚刚删除了virtualenv并重新制作了它。 pip3install = pip3 install -r requirements.txt

[mything] cchilders@cchilders-desktop:~/projects/mything (master) 
$ cat requirements.txt 
Django==1.10.1
django-filter
djangorestframework
psycopg2
twilio
ipdb
ipython


[mything] cchilders@cchilders-desktop:~/projects/mything (master) 
$ pip3install 
Collecting Django==1.10.1 (from -r requirements.txt (line 1))
  Using cached Django-1.10.1-py2.py3-none-any.whl
Collecting django-filter (from -r requirements.txt (line 2))
  Using cached django_filter-0.15.2-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): djangorestframework in /home/cchilders/.local/lib/python3.5/site-packages (from -r requirements.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /usr/lib/python3/dist-packages (from -r requirements.txt (line 4))
Collecting twilio (from -r requirements.txt (line 5))
Requirement already satisfied (use --upgrade to upgrade): ipdb in /home/cchilders/.local/lib/python3.5/site-packages (from -r requirements.txt (line 6))
Requirement already satisfied (use --upgrade to upgrade): ipython in /home/cchilders/.local/lib/python3.5/site-packages (from -r requirements.txt (line 7))
Collecting pysocks; python_version == "3.5" (from twilio->-r requirements.txt (line 5))
Requirement already satisfied (use --upgrade to upgrade): six in /home/cchilders/.local/lib/python3.5/site-packages (from twilio->-r requirements.txt (line 5))
Collecting httplib2>=0.7 (from twilio->-r requirements.txt (line 5))
Requirement already satisfied (use --upgrade to upgrade): pytz in /usr/lib/python3/dist-packages (from twilio->-r requirements.txt (line 5))
Requirement already satisfied (use --upgrade to upgrade): setuptools in /home/cchilders/.local/lib/python3.5/site-packages (from ipdb->-r requirements.txt (line 6))
Requirement already satisfied (use --upgrade to upgrade): prompt-toolkit<2.0.0,>=1.0.3 in /home/cchilders/.local/lib/python3.5/site-packages (from ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): pickleshare in /home/cchilders/.local/lib/python3.5/site-packages (from ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): decorator in /home/cchilders/.local/lib/python3.5/site-packages (from ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): simplegeneric>0.8 in /home/cchilders/.local/lib/python3.5/site-packages (from ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): traitlets>=4.2 in /home/cchilders/.local/lib/python3.5/site-packages (from ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): pygments in /home/cchilders/.local/lib/python3.5/site-packages (from ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): pexpect; sys_platform != "win32" in /home/cchilders/.local/lib/python3.5/site-packages (from ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): wcwidth in /home/cchilders/.local/lib/python3.5/site-packages (from prompt-toolkit<2.0.0,>=1.0.3->ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): ipython-genutils in /home/cchilders/.local/lib/python3.5/site-packages (from traitlets>=4.2->ipython->-r requirements.txt (line 7))
Requirement already satisfied (use --upgrade to upgrade): ptyprocess>=0.5 in /home/cchilders/.local/lib/python3.5/site-packages (from pexpect; sys_platform != "win32"->ipython->-r requirements.txt (line 7))
Installing collected packages: Django, django-filter, pysocks, httplib2, twilio
Exception:
Traceback (most recent call last):
  File "/home/cchilders/.local/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/cchilders/.local/lib/python3.5/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/home/cchilders/.local/lib/python3.5/site-packages/pip/req/req_set.py", line 742, in install
    **kwargs
  File "/home/cchilders/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/home/cchilders/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "/home/cchilders/.local/lib/python3.5/site-packages/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/home/cchilders/.local/lib/python3.5/site-packages/pip/wheel.py", line 287, in clobber
    ensure_dir(dest)  # common for the 'include' path
  File "/home/cchilders/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/site-packages'

左边的mything是一个活跃的虚拟现实(我只是重新制作)

4 个答案:

答案 0 :(得分:14)

你可能会因忘记将路径放到Python3解释器而意外地使用Python2重新创建virtualenv,因此当你执行pip3时它指的是系统Python3。

确保在virtualenv中使用正确的Python,并确保使用pip创建virtualenv(是的,这是默认选项,但我们不知道如何创建虚拟环境)。

答案 1 :(得分:10)

只是为了扩展@valentjedi的答案,这里是我如何在不使用sudo的情况下修复我的权限问题。

安装

  • 确保您已安装virtualenv here

  • 这是可选的,但我也使用virtualenvwrapper来使用workon命令here,否则你只能从virtualenv

  • source bin/activate

创建Virtualenv

您不希望使用sudo安装项目库,因为它会在系统范围内安装您的库(当您有多个项目时会遇到问题)。而是使用像这样的virtualenvs:

$mkvirtualenv myenv --python=python3.5
$workon myenv
$pip3 install -r requirements.txt

这可以让你通过制作自己的艺术家来实现这一目标。并指定您正在使用的python。然后激活环境并能够安装需求文件。

答案 2 :(得分:0)

即使我的virtualenv中有正确的python路径,我也遇到同样的问题。我的错误是使用了错误的pip版本-使用python3.7而不是 pip3.7 install -r requirements.txt < / p>

答案 3 :(得分:0)

我遇到了同样的错误

copying build/lib.linux-x86_64-3.8/pvectorc.cpython-38-x86_64-linux-gnu.so -> /home/insoluble/Workspace/venvs/your_venv/lib/python3.8/site-packages
    byte-compiling /home/insoluble/Workspace/venvs/your_venvlib/python3.8/site-packages/_pyrsistent_version.py to _pyrsistent_version.cpython-38.pyc
    error: [Errno 13] Permission denied: '/home/insoluble/Workspace/venvs/your_venv/lib/python3.8/site-packages/__pycache__/_pyrsistent_version.cpython-38.pyc.140572841931152'

确保在创建虚拟环境时不使用sudo。我在创建一个时犯了那个错误,因此是问题所在。

使用以下命令创建新环境后,解决了该问题。

python3.8 -m venv ~/Workspace/venvs/my_venv