我正在尝试使用 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 工作的正确方法是什么?