【问题标题】:Cannot create Virtualenv in Python无法在 Python 中创建 Virtualenv
【发布时间】:2018-01-09 11:12:21
【问题描述】:

我在 Python 中遇到了 virtualenv。

virtualenv _env 之后我得到:

Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/marcin/Documents/Projects/django_tutorial/_env/bin/python2
Also creating executable in /home/marcin/Documents/Projects/django_tutorial/_env/bin/python
Installing setuptools, pkg_resources, pip, wheel...
  Complete output from command /home/marcin/Documen...ial/_env/bin/python2 - setuptools pkg_resources pip wheel:
  Collecting setuptools
  Downloading setuptools-38.4.0-py2.py3-none-any.whl (489kB)
Exception:
Traceback (most recent call last):
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/share/python-wheels/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/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 821, in unpack_url
    hashes=hashes
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 659, in unpack_http_url
    hashes)
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 882, in _download_http_url
    _download_url(resp, link, content_file, hashes)
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 603, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/utils/hashes.py", line 46, in check_against_chunks
    for chunk in chunks:
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 571, in written_chunks
    for chunk in chunks:
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/utils/ui.py", line 139, in iter
    for x in it:
  File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 560, in resp_read
    decode_content=False):
  File "/home/marcin/Documents/Projects/django_tutorial/_env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/response.py", line 432, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/home/marcin/Documents/Projects/django_tutorial/_env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/response.py", line 397, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/marcin/Documents/Projects/django_tutorial/_env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/response.py", line 312, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
----------------------------------------
...Installing setuptools, pkg_resources, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 2375, in <module>
    main()
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 724, in main
    symlink=options.symlink)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 992, in create_environment
    download=download,
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 922, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 817, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /home/marcin/Documen...ial/_env/bin/python2 - setuptools pkg_resources pip wheel failed with error code 2

我有:

虚拟环境 15.1.0

点 9.0.1

Python 2.7.13

我没有想法。我尝试导出语言环境,重新安装 pip、setuptools 和 virtualenv。 你有什么建议吗?我将不胜感激。

【问题讨论】:

  • ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.。您可以访问该网站吗?
  • 这是一个超时错误。可能是网络问题。检查这个thread
  • 我设置了默认超时,我得到了同样的错误:(
  • 我在这里遇到了非常相似的问题,我得到的是 404 HTTPError: 404 Client Error: Not Found for url: http://mirrors.aliyun.com/pypi/simple/pkg-resources/。但是我发现任何镜像下都没有simple/pkg-resources目录,请问我该如何解决呢?

标签: python python-2.7 virtualenv


【解决方案1】:

如果您在中国,您可以更改您的pip 来源以解决此问题。

mkdir ~/.pip
echo '[global]' > ~/.pip/pip.conf
echo 'index-url = https://pypi.tuna.tsinghua.edu.cn/simple' >> ~/.pip/pip.conf

使用清华大学的镜子,或许可以解决你的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多