2021年9月

1.无法打包依赖了requests模块的应用(ImportError: No module named 'requests')
pyinstaller -F --hidden-import=requests script.py

2.oss2安装之后打包无法运行,提示缺少文件
修改spec文件,添加外部文件

如下图,在Analysis部分的datas中添加外部文件路径和打包的路径,如:

('/usr/local/bin/python3.5/site-packages/aliyunsdkcore/data/','aliyunsdkcore/data/')

前面是源文件路径(可用相对路径,也可以用绝对路径),后面是打包后的路径

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即可