我在尝试使用 IronPython 安装 autopep8 时遇到错误:
ImportError: No module named logilab
失败的代码片段是:
def load_module(self, fullname):
self._reopen()
try:
mod = imp.load_module(fullname, self.file, self.filename, self.etc)
finally:
if self.file:
self.file.close()
# Note: we don't set __loader__ because we want the module to look
# normal; i.e. this is just a wrapper for standard import machinery
return mod
使用解释器 ipy64 导入 logilab 没有失败。
我为文件名添加了一条打印语句,它显示:
C:\Program Files (x86)\IronPython 2.7\Lib\site-packages\logilab_common-0.59.1-py2.7.egg\logilab
该路径存在并且包含init.py 包含以下内容:
"""generated file, don't modify or your data will be lost"""
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
pass
我通过添加快速而肮脏地修复了错误
except ImportError:
mod = __import__(fullname)
但我对这个修复没有好感,因为我不知道可能的影响。
现在,为什么使用 imp.load_module 失败以及使用有什么区别import ?