在 Python3.6 虚拟环境中无法使用 pip install flask

在 Python3.6 虚拟环境中无法使用 pip install flask

我正在尝试遵循此处的 MS DevOps 教程:https://microsoft.github.io/PartsUnlimitedMRP/pandp/200.1x-PandP-LocustTest.html

我尝试过 Ubuntu 和 CentOS,都出现完全相同的失败:

(environment) [crimKidA@CentOS7 ~]$ pip install flask
Collecting flask
  Downloading https://files.pythonhosted.org/packages/9b/93/628509b8d5dc749656a9641f4caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl (94kB)
    100% |████████████████████████████████| 102kB 1.6MB/s
Collecting itsdangerous>=0.24 (from flask)
  Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Werkzeug>=0.15 (from flask)
  Downloading https://files.pythonhosted.org/packages/ba/a5/d6f8a6e71f15364d35678a4ec8a0186f980b3bd2545f40ad51dd26a87fb1/Werkzeug-1.0.0-py2.py3-none-any.whl (298kB)
    100% |████████████████████████████████| 307kB 2.0MB/s
Collecting Jinja2>=2.10.1 (from flask)
  Downloading https://files.pythonhosted.org/packages/27/24/4f35961e5c669e96f6559760042a55b9bcfcdb82b9bdb3c8753dbe042e35/Jinja2-2.11.1-py2.py3-none-any.whl (126kB)
    100% |████████████████████████████████| 133kB 3.0MB/s
Collecting click>=5.1 (from flask)
  Downloading https://files.pythonhosted.org/packages/dd/c0/4d8f43a9b16e289f36478422031b8a63b54b6ac3b1ba605d602f10dd54d6/click-7.1.1-py2.py3-none-any.whl (82kB)
    100% |████████████████████████████████| 92kB 5.1MB/s
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->flask)
  Downloading https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: itsdangerous, Werkzeug, MarkupSafe, Jinja2, click, flask
Exception:
Traceback (most recent call last):
  File "/path/to/new/virtual/environment/lib64/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/path/to/new/virtual/environment/lib64/python3.6/site-packages/pip/commands/install.py", line 365, in run
    strip_file_prefix=options.strip_file_prefix,
  File "/path/to/new/virtual/environment/lib64/python3.6/site-packages/pip/req/req_set.py", line 789, in install
    **kwargs
  File "/path/to/new/virtual/environment/lib64/python3.6/site-packages/pip/req/req_install.py", line 854, in install
    strip_file_prefix=strip_file_prefix
  File "/path/to/new/virtual/environment/lib64/python3.6/site-packages/pip/req/req_install.py", line 1069, in move_wheel_files
    strip_file_prefix=strip_file_prefix,
  File "/path/to/new/virtual/environment/lib64/python3.6/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/path/to/new/virtual/environment/lib64/python3.6/site-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/path/to/new/virtual/environment/lib64/python3.6/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib64/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/path/to/new/virtual/environment/lib/python3.6/site-packages/itsdangerous'

但是在虚拟环境中没有sudo,所以我很茫然:sudo: pip: command not found

我谷歌搜索此问题,没有找到任何结果。

答案1

我认为这里的问题是你已经创建了 vitualenv须藤特权或某人否则使用不同的用户帐户完成此操作。

尝试使用你自己的帐户重新创建新的虚拟环境,然后发出pip 安装通常情况下。

关于sudo:pip:未找到命令问题,发生这种情况是因为 pip 可执行文件未包含在 root 用户中小路环境变量,弄清楚这一点:

which pip

然后检查点子可执行路径包含在root用户中小路环境变量:

sudo env | grep ^PATH

相关内容