python - Pyinstaller 和 Pycrypto

标签 python pyinstaller pycrypto

我们最近将 pycrypto 添加到我们一直在进行的项目中,现在我无法在使用 pyinstaller 构建该软件后运行该软件。

我在 pyinstaller 中遇到了新包的问题,​​但我无法特别修复这个问题。

我在尝试运行构建的软件时遇到的错误如下(抱歉解释,构建需要相当长的时间)

一开始是这样的:

No package Crypto.Cipher

所以我将 'Crypto' 添加到我的 .spec 文件中的 hiddenimports。然后我得到了,

No module named Cipher

所以我将 'Crypto' 更改为 'Crypto.Cipher' 然后我得到了,

Crypto.Cipher has no attribute AES

所以我将 'Crypto.Cipher' 更改为 'Crypto.Cipher.AES' 然后我得到了

File "C:\Folder\made\by\pyinstaller\Crypto.Cipher.AES", line 49 in <module>
ImportError: cannot import name blockalgo

所以我将 'Crypto.Cipher.AES' 更改为 'Crypto.Cipher.AES.blockalgo' 并且错误没有改变。

我已经尝试了几种不同的配置,但是构建脚本的输出总是按照以下方式显示

ERROR: Hidden import 'blockalgo' not found.

有谁知道如何正确导入它,或者知道如何让 pycrypto 与 pyinstaller 配合使用?

最佳答案

根据 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似乎相关,答案可能对您也有用。

最后,this report似乎包含类似的问题。用户似乎能够通过更新到 pyinstaller 2.1 来修复它,因此如果您还没有尝试过,您可能想尝试一下。

关于python - Pyinstaller 和 Pycrypto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23233222/

相关文章:

python - PyInstaller 不包含导入

python - PyInstaller 和多处理

Python:来自已编译源代码的 ImportError

python - Pycrypto 的 Random.get_random_bytes 和一个简单的随机字节生成器有什么区别?

python - 如何使用 BeautifulSoup 抓取网页 url

python - Django-Pinax : How do you use a pinax app apart from what you get with a pinax base project?

python - 使用 AES-256 和 PKCS7 填充进行加密

java - 如何在Python中生成TrueLicence

Python sqlite3 select from 语句在获取时返回空列表

python - 过滤图像以提高文本识别