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 模块?

最佳答案

在以下位置提取 suds 蛋:



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

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

py2exe 构建成功完成。 imp.find_module 似乎需要包含模块源文件的目录才能存在,无法识别egg 文件。

关于python - 导入错误:没有名为 suds 的模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7403738/

10-12 17:24