PyInstaller'没有名为certifi的模块'错误

时间:2012-10-17 21:17:16

标签: python ssl pyinstaller

我正在尝试使用PyInstaller编译Python程序。当我尝试使用使用ssl的函数时,得到一个Import Error

ImportError: No module named certifi

我修改了.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'))

但后来我收到以下错误:

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

在使用PyInstaller编译时,将证书包含在使ssl工作的正确方法是什么?

1 个答案:

答案 0 :(得分:3)

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

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