py2exe错误:引发ImportError,“没有名为”的模块+ qname

时间:2014-01-05 01:02:42

标签: python py2exe

我有一个带有以下导入的python程序MyPictures.py

import os 
import gtk 
from os.path import isfile, join 
import shutil
import Image

我写了以下设置,py

from distutils.core import setup
import py2exe
#import os
import sys

__import__('gtk')
m = sys.modules['gtk']
gtk_base_path = m.__path__[0]

setup(
    name = 'MyPictures',
    description = 'Some handy tool',
    version = '1.0',

    windows = [
                  {
                      'script': 'MyPictures.py',
                  }
              ],

    options = {
                  'py2exe': {
                      'packages':'encodings',
                      'includes': 'cairo, pango, pangocairo, atk, gobject,',
                  }
              },
)  

我跑了

  

python.exe setup.py install

输出

运行安装运行构建运行install_egg_info删除 c:\ Python27 \ Lib \ site-packages \ MyPictures-1.0-py2.7.egg-info写作 C:\ Python27 \ LIB \站点包\ MyPictures-1.0-py2.7.egg-信息

然后我跑了

python.exe setup.py install

running install
running build
running install_egg_info
Removing c:\Python27\Lib\site-packages\MyPictures-1.0-py2.7.egg-info
Writing c:\Python27\Lib\site-packages\MyPictures-1.0-py2.7.egg-info

然后我跑了

python.exe setup.py py2exe

running py2exe
*** searching for required modules ***
Traceback (most recent call last):
  File "setup.py", line 37, in <module>
    'includes': 'cairo, pango, pangocairo, atk, gobject,',
  File "C:\Python27\Lib\distutils\core.py", line 152, in setup dist.run_commands()
  File "C:\Python27\Lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\Lib\distutils\dist.py", line 972, in run_command cmd_obj.run()
  File "c:\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run self._run()
  File "c:\Python27\lib\site-packages\py2exe\build_exe.py", line 296, in _run 
    self.find_needed_modules(mf, required_files, required_modules)
  File "c:\Python27\lib\site-packages\py2exe\build_exe.py", line 1297, in find_needed_modules mf.import_hook(mod)
  File "c:\Python27\lib\site-packages\py2exe\mf.py", line 719, in import_hook
    return Base.import_hook(self,name,caller,fromlist,level)
  File "c:\Python27\lib\site-packages\py2exe\mf.py", line 136, in import_hook
    q, tail = self.find_head_package(parent, name)
  File "c:\Python27\lib\site-packages\py2exe\mf.py", line 204, in find_head_package         raise ImportError, "No module named " + qname
ImportError: No module named

如何修复此错误?这是我第一次使用py2exe,提前感谢。

1 个答案:

答案 0 :(得分:3)

packagesincludes应为list类型。将options部分替换为:

    options = {
                  'py2exe': {
                      'packages':['encodings'],
                      'includes': ['cairo', 'pango', 'pangocairo', 'atk', 'gobject'],
                  }
              },