首页 > 解决方案 > setuptools pip wheel 失败,错误代码为 2

问题描述

我正在浏览 Google Cloud Platform 的Python Bookshelf App Tutorial,我正在启动我的 virtualenv,我被卡住了。

运行virtualenv -p python3 env会产生此错误:

⇒  virtualenv -p python3 env
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/puoygae/Lab/gae-bookshelf-app-python-flexible-experiment/getting-started-python/2-structured-data/env/bin/python3
Also creating executable in /Users/puoygae/Lab/gae-bookshelf-app-python-flexible-experiment/getting-started-python/2-structured-data/env/bin/python
Please make sure you remove any previous custom paths from your /Users/puoygae/.pydistutils.cfg file.
Installing setuptools, pip, wheel...
  Complete output from command /Users/puoygae/Lab/ga...data/env/bin/python3 - setuptools pip wheel:
  Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/75/b3/0a106dfaf7f48aef638da80b32608617cc8de4b24a22c8cd3759c32e5d30/setuptools-41.1.0-py2.py3-none-any.whl
Collecting pip
  Using cached https://files.pythonhosted.org/packages/8d/07/f7d7ced2f97ca3098c16565efbe6b15fafcba53e8d9bdb431e09140514b0/pip-19.2.2-py2.py3-none-any.whl
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
Installing collected packages: setuptools, pip, wheel
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/req/req_set.py", line 731, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/req/req_install.py", line 841, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/req/req_install.py", line 1040, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/wheel.py", line 343, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/wheel.py", line 321, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/Users/puoygae/Lab/gae-bookshelf-app-python-flexible-experiment/getting-started-python/2-structured-data/env/lib/python3.6/shutil.py", line 121, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/lib/python3.6/site-packages/easy_install.py'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 2327, in <module>
    main()
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 711, in main
    symlink=options.symlink)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 944, in create_environment
    download=download,
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 900, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 795, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/puoygae/Lab/ga...data/env/bin/python3 - setuptools pip wheel failed with error code 2

我已按照本指南设置我的 python 开发环境。我在互联网上搜索了一个解决方案,但我没有运气通过这一步。

是什么导致了问题,我该如何解决?

编辑:使用 sudo 运行它会产生以下错误:

⇒  sudo virtualenv -p python3 env
Password:
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/myUserName/Lab/gae-bookshelf-app-python-flexible-experiment/getting-started-python/2-structured-data/env/bin/python3
Not overwriting existing python script /Users/myUserName/Lab/gae-bookshelf-app-python-flexible-experiment/getting-started-python/2-structured-data/env/bin/python (you must use /Users/myUserName/Lab/gae-bookshelf-app-python-flexible-experiment/getting-started-python/2-structured-data/env/bin/python3)
Please make sure you remove any previous custom paths from your /Users/myUserName/.pydistutils.cfg file.
Installing setuptools, pip, wheel...
  Complete output from command /Users/myUserName/Lab/ga...data/env/bin/python3 - setuptools pip wheel:
  The directory '/Users/myUserName/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/myUserName/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting setuptools
  Downloading https://files.pythonhosted.org/packages/75/b3/0a106dfaf7f48aef638da80b32608617cc8de4b24a22c8cd3759c32e5d30/setuptools-41.1.0-py2.py3-none-any.whl (576kB)
Collecting pip
  Downloading https://files.pythonhosted.org/packages/8d/07/f7d7ced2f97ca3098c16565efbe6b15fafcba53e8d9bdb431e09140514b0/pip-19.2.2-py2.py3-none-any.whl (1.4MB)
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
Installing collected packages: setuptools, pip, wheel
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/req/req_set.py", line 731, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/req/req_install.py", line 841, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/req/req_install.py", line 1040, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/wheel.py", line 476, in move_wheel_files
    generated.extend(maker.make(spec))
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 353, in make
    self._make_script(entry, filenames, options=options)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 257, in _make_script
    self._write_script(scriptnames, shebang, script, filenames, ext)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 231, in _write_script
    self._fileop.write_binary_file(outname, script_bytes)
  File "/Library/Python/2.7/site-packages/virtualenv_support/pip-8.0.2-py2.py3-none-any.whl/pip/_vendor/distlib/util.py", line 388, in write_binary_file
    with open(path, 'wb') as f:
PermissionError: [Errno 1] Operation not permitted: '/bin/easy_install'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 2327, in <module>
    main()
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 711, in main
    symlink=options.symlink)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 944, in create_environment
    download=download,
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 900, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 795, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/myUserName/Lab/ga...data/env/bin/python3 - setuptools pip wheel failed with error code 2

标签: pythongoogle-app-enginegoogle-cloud-platform

解决方案


@puoygae 通过在他的 MacOS 上创建一个新的用户帐户并单独安装 python 来解决他的问题。他的管理员帐户中的环境令人费解。

对此已知问题的其他修复可以是:

  • 删除 /usr/local/lib/python2.7/dist-packages/ 中的所有 virtualenv* 内容,并根据此GitHub 问题重新安装它。
  • 从 pip 卸载任何 setuptools 和 wheel。也从以下位置卸载它们apt-get remove wheel setuptools virutalenv(如果它们存在,在某些情况下,wheels 和 setuptools 都可以存在,并且可能从 pip 和 apt-get 安装中相互冲突)> 从这里下载新的 setuptools-35.0.2 和从这里下载 virutalenv -15.1.0在这里。全新安装这两个工具。
  • 按照此处更新 openSSL 的说明进行操作,然后尝试使用 pip install 设置虚拟环境。
  • 可以尝试打开系统终端并键入 pip install virtualenv。重启IDE。
  • 尝试安装 pysocks - sudo pip install pysocks 使用 - unset all_proxy 重试
  • 您也可以尝试升级到 platformio-ide 2.1.5
  • “setenv all_proxy https://proxy_here:port_here/”。不仅解决了此设置的代理问题,而且解决了所有安装的代理问题。
  • 另请查看针对同一问题的此stackoverflow 线程修复程序。

参考链接:

https://github.com/platformio/platformio-atom-ide/issues/1245 https://github.com/pypa/virtualenv/issues/876


推荐阅读