我有一个使用ClientCookie和ClientForm的Python脚本。我需要通过py2exe创建一个可执行文件,所以我放置了#34; ClientCookie"和" ClientForm"在脚本的目录中创建名为" setup.py"的文件。具有以下内容:
from distutils.core import setup
import py2exe
setup(
console = ['some_script.py'],
options = {
'py2exe': {
'packages': ["ClientCookie", "ClientForm"]
}
}
)
当我尝试创建可执行文件时,它会出现以下错误:
> setup.py py2exe
*** searching for required modules ***
Traceback (most recent call last):
File "E:\projects\some_project\setup.py", line 9, in <module>
'packages': ["ClientCookie", "ClientForm"]
File "E:\software\Python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "E:\software\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "E:\software\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "E:\software\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run
self._run()
File "E:\software\Python27\lib\site-packages\py2exe\build_exe.py", line 296, in _run
self.find_needed_modules(mf, required_files, required_modules)
File "E:\software\Python27\lib\site-packages\py2exe\build_exe.py", line 1306, in find_needed_modules
mf.import_hook(f)
File "E:\software\Python27\lib\site-packages\py2exe\mf.py", line 719, in import_hook
return Base.import_hook(self,name,caller,fromlist,level)
File "E:\software\Python27\lib\site-packages\py2exe\mf.py", line 136, in import_hook
q, tail = self.find_head_package(parent, name)
File "E:\software\Python27\lib\site-packages\py2exe\mf.py", line 204, in find_head_package
raise ImportError, "No module named " + qname
ImportError: No module named ClientCookie
为什么呢?我究竟做错了什么?我该如何解决?
答案 0 :(得分:0)
不要在脚本目录中放置“ClientCookie”和“ClientForm”,而是按照以下步骤操作 -
1. 将它们放在“C:\ Python27 \ Lib \ site-packages”目录中(这是安装第三方库的默认目录)。此外,您似乎已手动创建了这些包,因此请仔细检查它们是否存在依赖性问题。
2. 将主python脚本和setup.py脚本放在python根文件夹中,即我的情况下为“C:\ Python27”。
3. 运行setup.py
注意:如果您仍遇到同样的问题,请尝试完全删除python和py2exe,然后重新安装。