试图在Windows 10机器和python 3.7.2中安装python包。我正在使用以下命令:
pip install numpy
它永远挂起。我尝试使用以下内容获取更多信息:
pip -vvv install numpy
这是结果:
Collecting numpy
1 location(s) to search for versions of numpy:
* https://pypi.org/simple/numpy/
Getting page https://pypi.org/simple/numpy/
Looking up "https://pypi.org/simple/numpy/" in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
https://pypi.org:443 "GET /simple/numpy/ HTTP/1.1" 304 0
我试图研究它但找不到任何东西。我不敢相信只有这个软件包会通过HTTPS,这就是为什么它失败了?
我和Django有同样的问题。
两个命令的输出中的差异如下:
pip install Django -vvv
...
Looking up "https://pypi.org/simple/django/" in the cache
Request header has "max_age" as 0, cache bypassed
https://pypi.org:443 "GET /simple/django/ HTTP/1.1" 304 0
<hangs here>
$ pip install Django --no-cache-dir -vvv
...
https://pypi.org:443 "GET /simple/django/ HTTP/1.1" 200 27460
<continues and successfully installs>
使用--no-cache-dir
只是绕过了问题。
当我手动删除缓存目录的内容时,就出现了解决方案。
rm -Rf ~/.cache/pip/*
允许pip install Django
按预期工作,缓存开始重建自己。
从docs,您可以根据您的操作系统找到缓存所在的路径:
缓存目录的默认位置取决于操作系统:
Unix的
~/.cache/pip and it respects the XDG_CACHE_HOME directory
。MACOS
~/Library/Caches/pip
。视窗
<CSIDL_LOCAL_APPDATA>\pip\Cache
哟可以尝试添加:
--no-cache-dir
默认情况下,在发出任何HTTP请求时,pip将首先检查其本地缓存,以确定它是否为该请求存储了尚未过期的合适响应。如果错误出现在该过程的那一部分中,则跳过该缓存检查应该可以解决问题。
官方pip documentation的详细信息。
作为解决方法,您可以手动下载并安装numpy
转到此处并选择您要安装的版本的.whl文件:https://pypi.org/simple/numpy/
下载后,您可以手动安装.whl:
pip install numpy-1.16.1-cp37-cp37m-win_amd64.whl