pycrypto打包错误

问题:

Pyinstaller 尝试使用 --key加密exe时得到以下错误
Traceback (most recent call last):
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 438, in get_code
    return self._pyz_archive.extract(fullname)[1]
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod02_archive.py", line 371, in extract
    obj = zlib.decompress(obj)
zlib.error: Error -3 while decompressing data: incorrect header check

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 25, in <module>
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 607, in exec_module
    bytecode = self.get_code(spec.loader_state)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 440, in get_code
    raise ImportError('Loader FrozenImporter cannot handle module ' + fullname)
ImportError: Loader FrozenImporter cannot handle module os
[5836] Failed to execute script pyiboot01_bootstrap

解决方案:

使用 pycryptodome 模块时 Pyinstaller --key 参数打包会出错,这应该是模块不兼容。

使用pycrypto模块来避免Loader FrozenImporter无法处理模块os错误。

在Windows上安装

  1. 安装Python 3.x.
  2. 安装Visual C ++生成工具
  3. 安装pycrypto模块
    cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build"
    vcvarsall.bat x86_amd64
    cd %VCINSTALLDIR%
    for /R %f in (*stdint.h) do set CL=-FI"%f"
    pip install pycrypto

这将工作并能够使用.spec文件或直接加密可执行文件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章