How to build executable with pyinstaller that uses pycryptodome?

守給你的承諾、 提交于 2019-12-04 16:49:51

If you want to solve your problems use pycryptodomex

pip uninstall -y pycryptodome
pip install pycryptodomex

Then search and all the imports of Crypto and replace them with Cryptodome.

You may need a more recent version of PyInstaller - there was a 'hook' added for pycryptodome three months ago https://github.com/pyinstaller/pyinstaller/tree/develop/PyInstaller/hooks

After adding the hook I had additional issues and was able to get it working by installing cffi package https://pypi.python.org/pypi/cffi

pip install cffi

It works using pyinstaller 3.4 as installed by pip on conda 4.5.12:

>conda create -n pyinstaller python=3.7
>activate pyinstaller
>pip install pyinstaller
>pip install pycryptodome
>conda list 
# packages in environment at C:\Users\pablo\AppData\Local\Continuum\anaconda3\envs\pyinstaller:
#
# Name                    Version                   Build  Channel
altgraph                  0.16.1                    <pip>
ca-certificates           2018.03.07                    0
certifi                   2018.11.29               py37_0
future                    0.17.1                    <pip>
macholib                  1.11                      <pip>
openssl                   1.1.1a               he774522_0
pefile                    2018.8.8                  <pip>
pip                       18.1                     py37_0
pycryptodome              3.7.2                     <pip>
PyInstaller               3.4                       <pip>
python                    3.7.2                h8c8aaf0_0
pywin32-ctypes            0.2.0                     <pip>
setuptools                40.6.3                   py37_0
sqlite                    3.26.0               he774522_0
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.15.26706          h3a45250_0
wheel                     0.32.3                   py37_0
wincertstore              0.2                      py37_0
>
>pyinstaller main.py
62 INFO: PyInstaller: 3.4
62 INFO: Python: 3.7.2
62 INFO: Platform: Windows-10-10.0.15063-SP0
62 INFO: wrote C:\Users\pablo\Dev\untitled\main.spec
78 INFO: UPX is not available.
78 INFO: Extending PYTHONPATH with paths
['C:\\Users\\pablo\\Dev\\untitled', 'C:\\Users\\pablo\\Dev\\untitled']
78 INFO: checking Analysis
78 INFO: Building Analysis because Analysis-00.toc is non existent
78 INFO: Initializing module dependency graph...
78 INFO: Initializing module graph hooks...
78 INFO: Analyzing base_library.zip ...
2734 INFO: running Analysis Analysis-00.toc
2734 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\pablo\appdata\local\continuum\anaconda3\envs\pyinstaller\python.exe
3390 INFO: Caching module hooks...
3406 INFO: Analyzing C:\Users\pablo\Dev\untitled\main.py
3671 INFO: Loading module hooks...
3671 INFO: Loading module hook "hook-Crypto.py"...
3687 INFO: Loading module hook "hook-encodings.py"...
3765 INFO: Loading module hook "hook-pydoc.py"...
3765 INFO: Loading module hook "hook-xml.py"...
3953 INFO: Looking for ctypes DLLs
3953 INFO: Analyzing run-time hooks ...
3968 INFO: Looking for dynamic libraries
4859 INFO: Looking for eggs
4859 INFO: Using Python library c:\users\pablo\appdata\local\continuum\anaconda3\envs\pyinstaller\python37.dll
4859 INFO: Found binding redirects:
[]
4875 INFO: Warnings written to C:\Users\pablo\Dev\untitled\build\main\warn-main.txt
4906 INFO: Graph cross-reference written to C:\Users\pablo\Dev\untitled\build\main\xref-main.html
4937 INFO: checking PYZ
4937 INFO: Building PYZ because PYZ-00.toc is non existent
4937 INFO: Building PYZ (ZlibArchive) C:\Users\pablo\Dev\untitled\build\main\PYZ-00.pyz
5484 INFO: Building PYZ (ZlibArchive) C:\Users\pablo\Dev\untitled\build\main\PYZ-00.pyz completed successfully.
5499 INFO: checking PKG
5499 INFO: Building PKG because PKG-00.toc is non existent
5499 INFO: Building PKG (CArchive) PKG-00.pkg
5515 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
5515 INFO: Bootloader c:\users\pablo\appdata\local\continuum\anaconda3\envs\pyinstaller\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
5515 INFO: checking EXE
5515 INFO: Building EXE because EXE-00.toc is non existent
5515 INFO: Building EXE from EXE-00.toc
5515 INFO: Appending archive to EXE C:\Users\pablo\Dev\untitled\build\main\main.exe
5515 INFO: Building EXE from EXE-00.toc completed successfully.
5531 INFO: checking COLLECT
5531 INFO: Building COLLECT because COLLECT-00.toc is non existent
5531 INFO: Building COLLECT COLLECT-00.toc
6062 INFO: Building COLLECT COLLECT-00.toc completed successfully.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!