使用pip安装flask时获得权限被拒绝错误

时间:2018-05-22 12:51:08

标签: python pip

我尝试在Arch Linux上运行pip install flask,我收到以下错误:

Collecting itsdangerous>=0.24 (from flask)
  Using cached https://files.pythonhosted.org/packages/dc/b4/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4/itsdangerous-0.24.tar.gz
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->flask)
  Using cached https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz
Installing collected packages: Werkzeug, click, MarkupSafe, Jinja2, itsdangerous, flask
  Running setup.py install for MarkupSafe ... done
  Running setup.py install for itsdangerous ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-9u23zlnf/itsdangerous/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-r51zrnnv-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib
    copying itsdangerous.py -> build/lib
    running install_lib
    copying build/lib/itsdangerous.py -> /usr/lib/python3.6/site-packages
    byte-compiling /usr/lib/python3.6/site-packages/itsdangerous.py to itsdangerous.cpython-36.pyc
    error: [Errno 13] Permission denied: '/usr/lib/python3.6/site-packages/__pycache__/itsdangerous.cpython-36.pyc.140591598548528'

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-9u23zlnf/itsdangerous/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-r51zrnnv-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-9u23zlnf/itsdangerous/
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.`

这个错误是什么意思?

2 个答案:

答案 0 :(得分:3)

使用

pip install --user flask

代替。

您将收到“拒绝权限”错误,这意味着您无权写入特定位置。

当您使用pip install flask时,pip会尝试在flask的某处安装软件包/usr/lib/python3.6/../。此目录需要root访问权限,这是您在运行pip install flask时没有的内容。

通过使用--user标志,您告诉pip将软件包安装到您的主目录,该目录不需要root权限。

使用--user标志安装Python软件包始终是一个好习惯,因为您不是在系统范围内安装该软件包。当您使用sudo pip install package_name时,您将在系统范围内安装/升级包(具有依赖项)。 Python在一些系统中启动关键系统组件,迫使系统安装新版本的软件包可能会破坏一些关键的系统组件。通常,系统只是为了支持向后兼容而停留在特定的软件包版本上,如果你尝试将其安装为sudo,可能会破坏它。

答案 1 :(得分:0)

错误:无法执行“--user”安装。用户站点包在此 virtualenv 中不可见。