打包版本python3.5 32位
pyinstaller 3.2.1
C:\Users\sxed\PycharmProjects\dabao_ok>C:\Users\sxed\PycharmProjects\dabao_ok\di
st\XL\XL.exe
Traceback (most recent call last):
File "XL.py", line 1, in <module>
import ReadExcel
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.p
y", line 714, in load_module
module = loader.load_module(fullname)
File "ReadExcel.py", line 13, in init ReadExcel
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.p
y", line 714, in load_module
module = loader.load_module(fullname)
File "jiami.py", line 6, in init jiami
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.p
y", line 631, in exec_module
exec(bytecode, module.__dict__)
File "Crypto\Hash\SHA.py", line 24, in <module>
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.p
y", line 631, in exec_module
exec(bytecode, module.__dict__)
File "Crypto\Hash\SHA1.py", line 47, in <module>
File "Crypto\Util\_raw_api.py", line 258, in load_pycryptodome_raw_lib
OSError: Cannot load native module 'Crypto.Hash._SHA1': Trying '_SHA1.cp35-win32
.pyd': Failed to load dynlib/dll 'C:\\Users\\sxed\\PycharmProjects\\dabao_ok\\di
st\\XL\\Crypto\\Util\\..\\Hash\\_SHA1.cp35-win32.pyd'. Most probably this dynlib
/dll was not found when the application was frozen., Trying '_SHA1.pyd': Failed
to load dynlib/dll 'C:\\Users\\sxed\\PycharmProjects\\dabao_ok\\dist\\XL\\Crypto
\\Util\\..\\Hash\\_SHA1.pyd'. Most probably this dynlib/dll was not found when t
he application was frozen.
[4220] Failed to execute script XL
提示缺少Crypto中的包,显示检查hiddent-import,发现该导入的都已经导入了,但是打包之后还是出现错误。
最后在英文网站发现需要增加hook文件:
import os
import glob
from PyInstaller.compat import EXTENSION_SUFFIXES
from PyInstaller.utils.hooks import get_module_file_attribute
binaries = []
binary_module_names = [
'Crypto.Math', # First in the list
'Crypto.Cipher',
'Crypto.Util',
'Crypto.Hash',
'Crypto.Protocol',
]
try:
for module_name in binary_module_names:
m_dir = os.path.dirname(get_module_file_attribute(module_name))
for ext in EXTENSION_SUFFIXES:
module_bin = glob.glob(os.path.join(m_dir, '_*%s' % ext))
for f in module_bin:
binaries.append((f, module_name.replace('.', os.sep)))
except ImportError:
# Do nothing for PyCrypto (Crypto.Math does not exist there)
pass
保存为hook-Crypto.py文件放到~\Lib\site-packages\PyInstaller\hooks文件夹下,
重新打包,即可解决问题。