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文件或直接加密可執行文件。

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