我有一个运行良好的Python应用程序。现在,我使用py2exe创建此应用程序的Windows可执行文件,但是生成的exe失败,并抱怨它缺少configobj模块

Traceback (most recent call last):
  File "file1.py", line 1, in <module>
  File "file2.pyc", line 10, in <module>
ImportError: No module named configobj


file2.py中的第10行仅仅是from configobj import ConfigObj

我尝试通过指定-i configobj参数将configobj显式添加到打包模块的列表中,但是py2exe运行失败,并出现类似错误:

running py2exe
creating  C:\path\to\proj\dist
*** generate typelib stubs ***
collected 0 stubs from 1 type libraries
*** searching for required modules ***
Traceback (most recent call last):
  File " C:\path\to\proj\py2exe_setup.py", line 18, in <module>
    options = {"py2exe": {"typelibs": [('{00020813-0000-0000-C000-000000000046}', 0, 1, 5)]}},
  File "C:\Python26\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python26\lib\distutils\dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "C:\Python26\lib\distutils\dist.py", line 995, in run_command
    cmd_obj.run()
  File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 296, in _run
    self.find_needed_modules(mf, required_files, required_modules)
  File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 1297, in find_needed_modules
    mf.import_hook(mod)
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 719, in import_hook
    return Base.import_hook(self,name,caller,fromlist,level)
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 136, in import_hook
    q, tail = self.find_head_package(parent, name)
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 204, in find_head_package
    raise ImportError, "No module named " + qname
ImportError: No module named configobj


configobj模块安装在我的计算机上的默认位置

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import configobj
>>> print configobj.__version__
4.7.2
>>> import py2exe
C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated
  import sets
>>> print py2exe.__version__
0.6.9


我究竟做错了什么 ?

最佳答案

从源代码重新安装configobj可以解决此问题。如果我知道为什么

关于python - py2exe找不到模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7298937/

10-11 07:38