pyinstaller 在支持python3.6+出现OSError:Cannot load native module 'Crypto.Cipher._raw_ecb'的一种解决方法

OSError:Cannot load native module 'Crypto.Cipher._raw_ecb':Trying '_raw_ecb.cp36-win_amd64.pyd':cannot load library 'C:\Users\admin\AppData\Local\Temp\_MEI160382\Crypto\Util\..\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.63\Lib\site-packages\PyInstaller\hooks中

3.重启该cmd即可

你可能感兴趣的:(python)