ImportError:没有名为suds的模块

时间:2011-09-13 14:42:21

标签: python import path suds importerror

在py2exe导入suds模块时遇到问题,并将其缩小到以下范围:

>>> imp.find_module('suds', sys.path)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named suds

但是,一个简单的导入工作正常:

>>> import suds
>>> suds.__version__
'0.4'

这是我的sys.path,它在'C:\ Python27 \ lib \ site-packages \ suds-0.4-py2.7.egg'中显示suds:

>>> pprint.pprint(sys.path)
['',
 'C:\\Python27\\lib\\site-packages\\pyyaml-3.10-py2.7-win32.egg',
 'C:\\Python27\\lib\\site-packages\\progressbar-2.3-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\sqlalchemy-0.7.2-py2.7-win32.egg',
 'C:\\Python27\\lib\\site-packages\\soappy-0.12.5-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\wstools-0.3-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\fpconst-0.7.2-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\python_ntlm-1.0.1-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\django-1.3-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\pyodbc-2.1.9-py2.7-win32.egg',
 'C:\\Python27\\lib\\site-packages\\suds-0.4-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages']

确认py2exe安装在2.7:

C:\Python27\Lib\site-packages>ls -l py2*
-rw-rw-rw-  1 BEARGLE 0  524 2008-11-10 14:40 py2exe-0.6.9-py2.7.egg-info

py2exe:
total 448
-rw-rw-rw-  1 BEARGLE 0  3092 2008-11-10 14:39 __init__.py
-rw-rw-rw-  1 BEARGLE 0  3177 2011-09-12 14:36 __init__.pyc
-rw-rw-rw-  1 BEARGLE 0  3177 2011-09-12 14:35 __init__.pyo
-rw-rw-rw-  1 BEARGLE 0  4582 2008-06-24 16:32 boot_com_servers.py
-rw-rw-rw-  1 BEARGLE 0  2898 2011-09-12 14:35 boot_com_servers.pyc
-rw-rw-rw-  1 BEARGLE 0  2898 2011-09-12 14:35 boot_com_servers.pyo
-rw-rw-rw-  1 BEARGLE 0  3584 2008-06-24 16:32 boot_common.py
-rw-rw-rw-  1 BEARGLE 0  2252 2011-09-12 14:35 boot_common.pyc
-rw-rw-rw-  1 BEARGLE 0  2252 2011-09-12 14:35 boot_common.pyo
-rw-rw-rw-  1 BEARGLE 0  2941 2008-06-24 16:32 boot_ctypes_com_server.py
-rw-rw-rw-  1 BEARGLE 0  2733 2011-09-12 14:35 boot_ctypes_com_server.pyc
-rw-rw-rw-  1 BEARGLE 0  2733 2011-09-12 14:35 boot_ctypes_com_server.pyo
-rw-rw-rw-  1 BEARGLE 0  7527 2008-06-24 16:32 boot_service.py
-rw-rw-rw-  1 BEARGLE 0  5081 2011-09-12 14:35 boot_service.pyc
-rw-rw-rw-  1 BEARGLE 0  4973 2011-09-12 14:35 boot_service.pyo
-rw-rw-rw-  1 BEARGLE 0 71838 2008-08-30 11:56 build_exe.py
-rw-rw-rw-  1 BEARGLE 0 48498 2011-09-12 14:35 build_exe.pyc
-rw-rw-rw-  1 BEARGLE 0 48330 2011-09-12 14:35 build_exe.pyo
-rw-rw-rw-  1 BEARGLE 0 30327 2011-09-13 09:16 mf.py
-rw-rw-rw-  1 BEARGLE 0 22999 2011-09-13 09:16 mf.pyc
-rw-rw-rw-  1 BEARGLE 0 22876 2011-09-12 14:35 mf.pyo
-rw-rw-rw-  1 BEARGLE 0 13312 2008-11-10 14:40 py2exe_util.pyd
drw-rw-rw-  2 BEARGLE 0  4096 2011-09-12 14:35 resources
-rwxrwxrwx  1 BEARGLE 0 17408 2008-11-10 14:40 run.exe
-rw-rw-rw-  1 BEARGLE 0 19456 2008-11-10 14:40 run_ctypes_dll.dll
-rw-rw-rw-  1 BEARGLE 0 19968 2008-11-10 14:40 run_dll.dll
-rw-rw-rw-  1 BEARGLE 0 20480 2008-11-10 14:40 run_isapi.dll
-rwxrwxrwx  1 BEARGLE 0 17408 2008-11-10 14:40 run_w.exe
drw-rw-rw-  8 BEARGLE 0  4096 2011-09-12 14:35 samples

为什么imp.find_module找不到suds模块?

1 个答案:

答案 0 :(得分:8)

提取suds鸡蛋:

  

C:\ Python27 \ lib中\站点包\泡沫-0.4-py2.7.egg

并创建包含源文件的C:\Python27\lib\site-packages\suds目录。现在找到模块:

>>> imp.find_module('suds')
(None, 'C:\\Python27\\lib\\site-packages\\suds', ('', '', 5))

py2exe构建成功完成。看来imp.find_module需要存在模块源文件的目录,不能识别egg文件。