You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Python 3.7.2环境下安装PyInstaller遇连接超时及版本匹配失败问题求助

解决PyInstaller安装超时及版本找不到的问题

先贴一下你遇到的错误日志:

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pyinstaller/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pyinstaller/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pyinstaller/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pyinstaller/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pyinstaller/
Could not find a version that satisfies the requirement pyinstaller (from versions: )
No matching distribution found for pyinstaller

我之前在Python 3.7环境下也碰到过一模一样的问题——本质不是真的没有适配的PyInstaller版本,而是默认的PyPI源访问速度太慢,超时后pip没能成功获取到版本列表,才会出现最后那两句错误。下面是几个亲测有效的解决办法:

方法一:切换国内PyPI镜像源(最推荐)

国内的镜像源访问速度快很多,直接在安装命令里指定源即可:

  • 阿里云源(稳定):
    pip install pyinstaller -i https://mirrors.aliyun.com/pypi/simple/
    
  • 清华源(更新快):
    pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple/
    
  • 豆瓣源:
    pip install pyinstaller -i https://pypi.douban.com/simple/
    

如果想永久切换源,也可以在用户目录下创建pip.conf(Linux/macOS)或pip.ini(Windows)文件,写入以下内容(以清华源为例):

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

方法二:延长pip的超时时间

如果不想换源,可以通过参数给pip更长的读取超时时间,避免因为网络波动导致超时:

pip install pyinstaller --default-timeout=100

方法三:先升级pip再安装

旧版本的pip可能存在网络兼容问题,先把pip升级到最新版本(同样建议用国内源),再安装PyInstaller:

pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install pyinstaller

方法四:手动下载安装包(兜底方案)

如果上面的方法都不行,可以手动下载适配Python 3.7的PyInstaller包(注意PyInstaller 5.x及以上版本不再支持Python 3.7,建议选4.x系列,比如4.10):

  1. 找到对应版本的.whl文件或源码包
  2. 切换到下载目录,执行安装命令:
    • 对于.whl文件:
      pip install PyInstaller-4.10-py3-none-any.whl
      
    • 对于源码包:
      pip install PyInstaller-4.10.tar.gz
      

补充提醒

Python 3.7已经是比较老的版本了,如果后续有条件,建议升级到更高版本的Python(比如3.8+),不仅能获得更好的兼容性,也能避免很多依赖安装的问题。

内容的提问来源于stack exchange,提问作者maor

火山引擎 最新活动