简体   繁体   English

PyInstaller“没有名为certifi的模块”错误

[英]PyInstaller 'no module named certifi' error

I'm trying to compile a Python program using PyInstaller. 我正在尝试使用PyInstaller编译Python程序。 When I try to use a function that uses ssl, a get an Import Error : 当我尝试使用使用ssl的函数时,出现Import Error

ImportError: No module named certifi

I've modified the .spec file in order to include the cacert.pem file from Python ssl library: 我修改了.spec文件,以包括来自Python ssl库的cacert.pem文件:

# -*- mode: python -*-
a = Analysis(['main.py'],
             pathex=['D:\\Projects\\soundcloud'],
             hiddenimports=[],
             hookspath=None)
a.datas.append(('cacert.pem', 'cacert.pem', 'DATA'))
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=1,
          name=os.path.join('build\\pyi.win32\\main', 'main.exe'),
          debug=False,
          strip=None,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=None,
               upx=True,
               name=os.path.join('dist', 'main'))

But then I get the following error: 但是然后我得到以下错误:

Traceback (most recent call last):
File "...\soundcloud\build\pyi.win32\main\out00-PYZ.pyz\api", line 186,
in run_api_thread
File "...\soundcloud\build\pyi.win32\main\out00-PYZ.pyz\api", line 40, 
in authenticate
File "...\soundcloud\build\pyi.win32\main\out00-PYZ.pyz\soundcloud.client", 
line 60,
in exchange_token
File "...\soundcloud\build\pyi.win32\main\out00-PYZ.pyz\soundcloud.request", 
line 173, in make_request
File "...\soundcloud\build\pyi.win32\main\out00-PYZ.pyz\requests.api", 
line 84, in post
File "...\soundcloud\build\pyi.win32\main\out00-PYZ.pyz\requests.api", 
line 39, in request
File "D:\Projects\soundcloud\build\pyi.win32\main\out00-PYZ.pyz\requests.sessions"
line 200, in request
File "D:\Projects\soundcloud\build\pyi.win32\main\out00-PYZ.pyz\requests.models",
line 537, in send
SSLError: [Errno 185090050] _ssl.c:336: 
error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

What is the right way to include the certificate in to make ssl work when compiled with PyInstaller? 使用PyInstaller进行编译时,包括证书以使ssl正常工作的正确方法是什么?

通过更改环境变量解决了该问题:

os.environ['REQUESTS_CA_BUNDLE'] = os.path.join(os.getcwd(), 'cacert.pem')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM