我无法使用 python-virtualenv 创建虚拟环境

我无法使用 python-virtualenv 创建虚拟环境

目前我已将我的笔记本电脑从 ubuntu 14.04 更新至 16.04 64bt 版本。

我已经安装了 python 2.7 和所有内容并尝试了所有操作,但是在 ubntu 14.04 上运行良好时,virtualevn 命令抛出了如下所示的错误,请提出建议并提出最佳解决方案来解决它。

目前我已尝试了很多方法来解决这个问题,例如下面给出的方法:卸载setuptools和virutalenv以及许多依赖项,然后按照各种帖子的建议重新安装。

New python executable in /home/jai/Desktop/jai/jai/bin/python
Installing setuptools, pip, wheel...
  Complete output from command /home/jai/Desktop/jai/jai/bin/python - setuptools pip wheel:
  Collecting setuptools
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/commands/install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/index.py", line 792, in get_page
    "Cache-Control": "max-age=600",
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py", line 488, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 386, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/adapter.py", line 47, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/adapters.py", line 390, in send
    conn = self.get_connection(request.url, proxies)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/adapters.py", line 290, in get_connection
    proxy_manager = self.proxy_manager_for(proxy)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/adapters.py", line 184, in proxy_manager_for
    **proxy_kwargs
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/adapters.py", line 43, in SOCKSProxyManager
    raise InvalidSchema("Missing dependencies for SOCKS support.")
InvalidSchema: Missing dependencies for SOCKS support.
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==15.1.0', 'console_scripts', 'virtualenv')()
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv.py", line 713, in main
    symlink=options.symlink)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv.py", line 945, in create_environment
    download=download,
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv.py", line 901, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv-15.1.0-py2.7.egg/virtualenv.py", line 797, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /home/jai/Desktop/jai/jai/bin/python - setuptools pip wheel failed with error code 2

答案1

这里的问题(正如我所看到的)是您试图使用 python 2.7 来运行 virtualenv,而从我们 10.10 之后的 ubuntu/debian 分支用户的角度来看,virtualenv 的全部意义在于能够在我们的 python 3(预安装并作为系统的一部分)环境中编译 python 2.7 程序,而无需在本地安装 python 2.7(这几乎总是会使系统变得混乱而无法修复)。

我在这里看到的第二个不好的做法是 ubuntu 更新。看起来它在这里有效(但同样,此功能几乎总是不起作用,并且会弄乱您的系统),但您应该使用 Live USB 安装方法来升级到新版本。

无论如何,我建议检查几个使 Python 2.7 编译工作的先决条件:

需要启用 32 位架构:

sudo dpkg --add-architecture i386

pip 需要保持最新(安装不会执行此操作,需要在安装后运行):

pip install --upgrade pip

您需要解决 pip 构建中的所有可能依赖项。可能的 MIA 包括:

libonig2 autoconf libtool pkg-config python-opengl python-imaging python-pyrex python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script libqt4-network libqt4-dbus python-pip python-qt4 python-qt4-gl python-numpy python-matplotlib libgle3 python-dev libssl-dev libffi-dev libxslt-dev libxml2-dev libxslt1-dev zlib1g-dev python-ipaddress python-enum34 python-pathlib python-py python-pycparser python-dateutil python-cffi libappindicator1 python-gpgme libindicator7 wget  libgl1-mesa-dri:i386 libgl1-mesa-glx:i386 libc6:i386 liblua5.1-0-dev liblua50-dev liblualib50-dev python-pyside.qtwebkit libgnutls30 libgnutls30:i386 virtualenv build-essential dh-make

要安装其中一些,您需要合作伙伴多元宇宙和基本的 apt-get 设置:

sudo sed -i 's/# deb http:\/\/archive.canonical.com/deb http:\/\/archive.canonical.com/' /etc/apt/sources.list
yes N | sudo dpkg --configure -a
#only if necessary
#sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"

并且在运行其他 pip 命令之前您需要进入 virtualenv 内部。

祝你好運!:)

答案2

经过长时间的努力,我找到了一个解决方案,如果将来有人遇到困难,可以按照以下步骤操作:

我遇到了同样的问题,然后我发现所有这一切都是因为安装工具和轮子而发生的:

  1. 我已经从 pip 中卸载了 setuptools 和 wheels
  2. 也可以从“apt-get remove wheel setuptools virutalenv”中删除(如果它们存在,在我的情况下,wheels 和 setuptools 都存在,并且可能与 pip 和 apt-get 安装相互冲突)
  3. 下载

  4. 重新安装这两个工具

此方法解决了我的台式机和笔记本电脑上的问题。
我也在此处发布了此解决方案:

https://github.com/pypa/virtualenv/issues/876

相关内容