首页 > 解决方案 > 使用 pip 安装烧瓶时出现权限被拒绝错误

问题描述

我尝试pip install flask在 Arch Linux 上运行,但出现以下错误:

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.`

这个错误是什么意思?

标签: pythonpip

解决方案


利用

pip install --user flask

反而。

您收到 Permission Denied 错误,这意味着您无权写入特定位置。

当你在使用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,则可能会破坏这一点。


推荐阅读