这是我的Python 3.3的setup.py文件:
#/usr/bin/env python3
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"packages": [
"os","io","copy","struct","hashlib","random",
"urllib","pycurl","json","Crypto"
],
"includes": [ "urllib.parse", ],
"excludes": ["tkinter"],
"icon":"backup.ico"
}
setup( name = "BlindBackup",
version = "1.0",
description = "BlindBackup client",
options = {"build_exe": build_exe_options},
executables = [Executable("backup.py", base=None)])
我可以执行“py -3 setup.py build_exe”但exe不起作用。通过启动生成的backup.exe,我收到以下错误消息:
ImportError: No module named 'Crypto.Cipher'; Crypto is not a package
然而,Crypto是一个包!我还尝试将这些添加到包含部分:
"includes": ["urllib.parse",
"Crypto","Crypto.Cipher","Crypto.Cipher.AES",],
但是我甚至无法构建exe:
File "C:\Python33\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
distutils.core.setup(**attrs)
File "C:\Python33\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python33\lib\distutils\dist.py", line 929, in run_commands
self.run_command(cmd)
File "C:\Python33\lib\distutils\dist.py", line 948, in run_command
cmd_obj.run()
File "C:\Python33\lib\site-packages\cx_Freeze\dist.py", line 232, in run
freezer.Freeze()
File "C:\Python33\lib\site-packages\cx_Freeze\freezer.py", line 603, in Freeze
self.finder = self._GetModuleFinder()
File "C:\Python33\lib\site-packages\cx_Freeze\freezer.py", line 343, in _GetMouleFinder
finder.IncludeModule(name)
File "C:\Python33\lib\site-packages\cx_Freeze\finder.py", line 678, in IncludeModule
namespace = namespace)
File "C:\Python33\lib\site-packages\cx_Freeze\finder.py", line 386, in _ImportModule
raise ImportError("No module named %r" % name)
ImportError: No module named 'Crypto.Cipher'
这没有任何意义,因为有一个名为Crypto.Cipher的模块。
您可以使用python 3测试相同的setup.py脚本 - 只需创建一个backup.py脚本并将其放入:
from Crypto.Cipher import AES
有人建议我安装预编译的空间模块(参见Error executing the result of cx_freeze using pycrypto),但它也不起作用。我不想写一个7个月大的问题的评论,也许这就是我应该做的?无论如何,我现在有这个问题,我不能自己解决这个问题。请帮帮我!
答案 0 :(得分:0)
好的,我很傻。我在我的项目中创建了一个名为“crypto.py”的模块。确实,这个模块在Linux下是另一个模块。但是,在Windows下,程序包“Crypto”和模块“crypto”似乎是相同的。 cx_Freeze使他们感到困惑,并试图在crypto.py“packacge”下找到Cipher模块,这是一个模块。
将我的模块重构为另一个名称,现在它可以正常工作!