pipenv环境中解决Python找不到ssl模块问题

起因:使用pipenv打包项目,将anaconda的python解释器(64bit)作为创建虚拟环境源


现象1 :使用pipenv或pip install时报错

WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not avai lable.")': /simple/openssl/

Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple /openssl/: There was a problem confirming the ssl cert=None, status=None)) after connection broken by 'SSLErro r("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/openssl/


现象2:import ssl后报错

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "d:\anaconda\envs\py38_64\lib\ssl.py", line 98, in <module> import _ssl # if we can't import it, let the error propagate

解决方法:

将以下两个dll复制到Script文件夹

Libssl-1_1-x64.dll
Libcrypto-1_1-x64.dll

同时记录一些pyinstaller打包的经验:

  • pyinstaller 在不同的环境下 打包的东西不同(找不到问题的时候可以找一下其他地方的问题,先退一步,以退为进)
  • pipenv可以用于虚拟环境打包,注意根目录位置,似乎不能随意切换
  • upx禁用,避免一些dll错误
  • torch cpu版打包占用小