OSError:Cannot load native module 'Crypto.Cipher._raw_ecb':Trying '_raw_ecb.cp36-win_amd64.pyd':cannot load library 'C:UsersadminAppDataLocalTemp_MEI160382CryptoUtil..Cipher_raw_ecb.cp36-win_amb64.pyd'是在使用pyinstaller常出现的问题,现已解决,我出现这个问题是因为python通过pip3 install pyinstaller没有重定位Crypto的钩子
解决方法:
1.在github给出的解决方案中拷贝相关代码,在本地新建一个叫 hook-Crypto.py 的文件,并把拷贝的代码保存进改文件中
github解决方案网址:https://raw.githubusercontent.com/pyinstaller/pyinstaller/develop/PyInstaller/hooks/hook-Crypto.py
里面的相关代码:hook-Crypto.py
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
2.然后把该钩子放入你的python的库文件中,通常为:~python3.63Libsite-packagesPyInstallerhooks中
3.重启该cmd即可