Pyinstaller & Pycrypto

会有一股神秘感。 提交于 2019-12-01 06:07:50
kadu

According to the pyinstaller manual:

You can verify that hidden import is the problem by using Python's verbose imports flag. If the import messages say "module not found", but the warnproject.txt file has no "no module named..." message for the same module, then the problem is a hidden import.

Hidden imports are handled by hooking the module (the one doing the hidden imports) at Analysis time. Do this as follows:

  1. Create a file named hook-module.py (where module is the fully-qualified Python name, eg, hook-xml.dom.py) and place it somewhere. Remember the place as your private hooks directory.

  2. In the .spec file, pass your private hooks directory as hookspath argument to Analysis so will be searched. Example:

    a = Analysis(['myscript.py'], hookspath='/my/priv/hooks') In most cases the hook module will have only one line:

    hiddenimports = ['module1', 'module2'] When the Analysis finds this file, it will proceed exactly as though the module explicitly imported module1 and module2.

This question seems related, the answers might also be useful for you.

Finally, this report seems to contain a similar problem. The user seemingly was able to fix it by updating to pyinstaller 2.1, so you might want to give that a try if you haven't already.

Change? Why not add? Adding these to hiddenimport solved this issue: 'Crypto', 'Crypto.Cipher', 'Crypto.Cipher.AES', 'Crypto.Random',

From https://stackoverflow.com/a/48408950/4355695 : Use pycryptodomex instead of pycryptodome. And @galgalesh's comment below the OP's question gave why pycrypto should no longer to be used.

pip uninstall -y pycrypto
pip uninstall -y pycryptodome
pip install pycryptodomex

pycryptodomex gives a clearly disambiguous Cryptodome module to replace Crypto. So, in your .py programs, replace Crypto with Cryptodome:

from Cryptodome.PublicKey import RSA

I now ran pyinstaller afresh and it worked out properly. No need to do any special hiddenimports etc. In the dist folder, there's now a clear Crpytodome folder holding all the .pyd's.

This Answer :

From https://stackoverflow.com/a/48408950/4355695 : Use pycryptodomex instead of pycryptodome. And @galgalesh's comment below the OP's question gave why pycrypto should no longer to be used.

pip uninstall -y pycrypto pip uninstall -y pycryptodome pip install pycryptodomex

pycryptodomex gives a clearly disambiguous Cryptodome module to replace Crypto. So, in your .py programs, replace Crypto with Cryptodome:

from Cryptodome.PublicKey import RSA

I now ran pyinstaller afresh and it worked out properly. No need to do any special hiddenimports etc. In the dist folder, there's now a clear Crpytodome folder holding all the .pyd's.

Works perfectly for me !

Use pycryptodomex instead of pycrypto and it would work !

I think it's due to python 3.6 and major evolutions of pycrypto to work with ! Then it stop working with 2.7.16 !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!