简体   繁体   English

“PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/site-packages'” 安装 Django

[英]“PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/site-packages'” installing Django

I cannot install basic Django packages on Ubuntu.我无法在 Ubuntu 上安装基本的 Django 包。 I just deleted virtualenv and remade it.我刚刚删除了 virtualenv 并重新制作了它。 pip3install = pip3 install -r requirements.txt 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'

The mything at the left is an active virtualenv (I just remade)左边的mything是一个活跃的 virtualenv(我刚刚重新制作)

You could accidentally recreate virtualenv with Python2 by forgetting to put path to Python3 interpreter so when you execute pip3 it refers to system Python3.您可能会因为忘记放置 Python3 解释器的路径而意外地使用 Python2 重新创建 virtualenv,因此当您执行 pip3 时,它指的是系统 Python3。

Make sure that you use correct Python in your virtualenv and also make sure that you create virtualenv with pip (yes it's the default option but we don't know how you create your virtual environment).确保在 virtualenv 中使用正确的 Python,并确保使用 pip 创建 virtualenv(是的,这是默认选项,但我们不知道您如何创建虚拟环境)。

Just to expand on the answer by @valentjedi, here's how I got my permission issue fixed without using sudo.只是为了扩展@valentjedi 的答案,以下是我在不使用 sudo 的情况下解决权限问题的方法。

Install安装

  • Make sure you have virtualenv installed here确保您在此处安装virtualenv

  • This is optional, but I also use virtualenvwrapper to use the workon command here , otherwise you can just source bin/activate from the virtualenv这是可选的,但我也使用 virtualenvwrapper 在此处使用workon命令,否则您只需从 virtualenv 中获取source bin/activate

Create Virtualenv创建虚拟环境

You do not want to install your project libraries with sudo because it will install your libraries system wide (which will run into issues when you have more than one project).你不想用sudo安装你的项目库,因为它会在系统范围内安装你的库(当你有多个项目时会遇到问题)。 Instead use virtualenvs like this:而是像这样使用 virtualenvs:

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

This gets you setup by making your virtualenv 'myenv' and specifying which python you are using.这可以通过使您的 virtualenv 成为“myenv”并指定您正在使用的 python 来进行设置。 You then activate the environment and are able to install your requirements file.然后您激活环境并能够安装您的需求文件。

I had the same issue even though I had correct python path in my virtualenv.即使我的 virtualenv 中有正确的 python 路径,我也遇到了同样的问题。 My mistake though was to use wrong pip version - having python3.7 I was typing pip install -r requirements.txt instead of pip3.7 install -r requirements.txt我的错误是使用了错误的 pip 版本 - 使用 python3.7 我正在输入pip install -r requirements.txt而不是pip3.7 install -r requirements.txt

I was getting the same error我遇到了同样的错误

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'

Make sure you don't use sudo while creating a virtual environment.确保在创建虚拟环境时不要使用sudo I did that mistake while creating one, hence the problem.我在创建一个时犯了那个错误,因此出现了问题。

After creating a fresh environment using following command, It solved the problem.使用以下命令创建新环境后,它解决了问题。

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

暂无
暂无

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

相关问题 PermissionError: [Errno 13]: &#39;/usr/local/lib/python3.5/ - PermissionError: [Errno 13]: '/usr/local/lib/python3.5/ PermissionError: [Errno 13] 权限被拒绝:&#39;C:\\\\Program Files\\\\Python35\\\\Lib\\\\site-packages\\\\six.py&#39; - PermissionError: [Errno 13] Permission denied: 'C:\\Program Files\\Python35\\Lib\\site-packages\\six.py' 清除 usr/lib/python3.5/site-packages/ 后 DNF 和 YUM 不起作用 - DNF and YUM does not work after Purging usr/lib/python3.5/site-packages/ PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.8/dist-packages/grpc/__init__.py' - PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.8/dist-packages/grpc/__init__.py' 安装djangorestframework时出现错误-权限被拒绝:&#39;/ usr / lib / python2.7 / site-packages / djangorestframework-3.6.3.dist-info&#39; - Getting Error while installing djangorestframework - Permission denied: '/usr/lib/python2.7/site-packages/djangorestframework-3.6.3.dist-info' VersionConflict: (pip 9.0.2 (/usr/local/lib/python3.5/site-packages), Requirement.parse(&#39;pip==9.0.1&#39;) - VersionConflict: (pip 9.0.2 (/usr/local/lib/python3.5/site-packages), Requirement.parse('pip==9.0.1') Errno 13 权限被拒绝:&#39;/Library/Python/2.7/site-packages/test-easy-install-18954.pth&#39; - Errno 13 Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-18954.pth' PermissionError: [Errno 13] 权限被拒绝 - Python/Django Locallibrary - PermissionError: [Errno 13] Permission denied - Python/Django Locallibrary PermissionError:[Errno 13] Django 中的权限被拒绝 - PermissionError: [Errno 13] Permission denied in Django setuptools:从zip中删除lib / python3.5 / site-packages前缀 - setuptools: remove lib/python3.5/site-packages prefix from zip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM