Flask 安装 - 错误

Flask Installation - Error

我尝试在装有 Linux Mint 的 PC 上的虚拟环境中安装 Flask。结束时出现此错误:

*error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/itsdangerous.py'
---------------------------------------------------------------------- Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-cMPDih/itsdangerous/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-HIVrsp-record/install-record.txt
--single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-cMPDih/itsdangerous/*

错误消息表明,您没有在虚拟环境中工作。你可能还没有激活它。您可以轻松测试和激活它:

$ which python
/usr/bin/python # oops, no virtual environment
$ source /home/user/venv/bin/activate
$ which python
/home/user/venv/bin/python # correct
$ pip install flask

每次都需要激活。您可以创建一个启动脚本,例如在 bash 中以在 运行 一个程序时激活它:

#!/bin/bash
source /home/user/venv/bin/activate
python /home/user/venv/myproject/main.py