python 创建虚拟环境时报错OSError, setuptools下载失败

Posted 桑胡

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 创建虚拟环境时报错OSError, setuptools下载失败相关的知识,希望对你有一定的参考价值。

错误信息如下:

Using base prefix ‘c:\users\huful\appdata\local\programs\python\python36-32‘
New python executable in E:LearningPythonsearchScriptspython.exe
Installing setuptools, pip, wheel...
Complete output from command E:LearningPythonsearchScriptspython.exe - setuptools pip wheel:
Collecting setuptools
Using cached https://files.pythonhosted.org/packages/96/06/c8ee69628191285ddddffb277bd5abdf769166e7a14b867c2a172f0175b1/setuptools-40.4.3-py2.py3-none-any.whl
Collecting pip
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
Exception:
Traceback (most recent call last):
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpip\_vendorurllib3 esponse.py", line 302, in _error_catcher
yield
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpip\_vendorurllib3 esponse.py", line 384, in read
data = self._fp.read(amt)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpip\_vendorcachecontrolfilewrapper.py", line 60, in read
data = self.__fp.read(amt)
File "c:usershufulappdatalocalprogramspythonpython36-32Libhttpclient.py", line 449, in read
n = self.readinto(b)
File "c:usershufulappdatalocalprogramspythonpython36-32Libhttpclient.py", line 493, in readinto
n = self.fp.readinto(b)
File "c:usershufulappdatalocalprogramspythonpython36-32Libsocket.py", line 586, in readinto
return self._sock.recv_into(b)
File "c:usershufulappdatalocalprogramspythonpython36-32Libssl.py", line 1002, in recv_into
return self.read(nbytes, buffer)
File "c:usershufulappdatalocalprogramspythonpython36-32Libssl.py", line 865, in read
return self._sslobj.read(len, buffer)
File "c:usershufulappdatalocalprogramspythonpython36-32Libssl.py", line 625, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpipasecommand.py", line 215, in main
status = self.run(options, args)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpipcommandsinstall.py", line 324, in run
requirement_set.prepare_files(finder)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpip eq eq_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpip eq eq_set.py", line 620, in _prepare_file
session=self.session, hashes=hashes)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpipdownload.py", line 821, in unpack_url
hashes=hashes
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpipdownload.py", line 659, in unpack_http_url
hashes)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpipdownload.py", line 882, in _download_http_url
_download_url(resp, link, content_file, hashes)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpipdownload.py", line 603, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpiputilshashes.py", line 46, in check_against_chunks
for chunk in chunks:
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpipdownload.py", line 571, in written_chunks
for chunk in chunks:
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpiputilsui.py", line 139, in iter
for x in it:
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpipdownload.py", line 560, in resp_read
decode_content=False):
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpip\_vendorurllib3 esponse.py", line 436, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpip\_vendorurllib3 esponse.py", line 401, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "c:usershufulappdatalocalprogramspythonpython36-32Libcontextlib.py", line 100, in __exit__
self.gen.throw(type, value, traceback)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv_supportpip-9.0.3-py2.py3-none-any.whlpip\_vendorurllib3 esponse.py", line 307, in _error_catcher
raise ReadTimeoutError(self._pool, None, ‘Read timed out.‘)
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org‘, port=443): Read timed out.
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "c:usershufulappdatalocalprogramspythonpython36-32lib unpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:usershufulappdatalocalprogramspythonpython36-32lib unpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:UsershufulAppDataLocalProgramsPythonPython36-32Scriptsvirtualenv.exe\__main__.py", line 9, in <module>
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv.py", line 712, in main
symlink=options.symlink)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv.py", line 953, in create_environment
download=download,
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv.py", line 904, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "c:usershufulappdatalocalprogramspythonpython36-32libsite-packagesvirtualenv.py", line 796, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command E:LearningPythonsearchScriptspython.exe - setuptools pip wheel failed with error code 2

总结错误信息内容,是在 Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)之时报的错,表达的意思大致是模块下载太慢导致的网络问题,试了很多次仍然无法创建虚拟环境。
网上有的博客说可能是中文路径、pip需要升级、python安装路径中有空格等,都没能解决问题。

最后使用 virtualenv myenv --no-setuptools 成功创建虚拟环境,创建虚拟环境后又在虚拟环境下使用 pip install setuptools命令给虚拟环境装上setuptools.

可是下载模块的时候明明是pip下载失败,我不安装setuptools反而创建虚拟环境成功,并且立马再创建其他的虚拟环境也能成功,这其中究竟是什么原理就不清楚了。

 




















































































以上是关于python 创建虚拟环境时报错OSError, setuptools下载失败的主要内容,如果未能解决你的问题,请参考以下文章

yolov5训练时报错 OSError: [WinError 1455] 页面文件太小,无法完成操作。 Error loading

pycharm新建django项目时报错

python使用requests时报错requests.exceptions.SSLError: HTTPSConnectionPool

已解决:python3.6 使用pip命令安装tornado时报错。

Ubuntu18.0 解决python虚拟环境中不同用户下或者python多版本环境中指定虚拟环境的使用问题

vscode切换虚拟环境报错无法加载文件 E:Python_projectshop_envScriptsActivate.ps1,因为在此系统上禁止运行 脚本。