为什么imp找不到“粘贴”模块?

2024-09-28 05:21:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个奇怪的问题:

我已成功安装粘贴。“进口浆糊”也可以。在

但我注意到小鬼找不到它。 "imp.find_模块('paste')“总是给出“ImportError:没有名为paste的模块”。在

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import imp
>>> imp.find_module('paste')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named paste
>>> import paste

我在三台不同的机器(Ubuntu14.04,windows10,windowsxp)上测试过,它们都有类似的问题。在


Tags: 模块importdefault粘贴onfindjunpaste
2条回答

我重复了这种行为。我觉得有点奇怪。文档描述了find_module()行为中的一些细微差异,但似乎没有突出显示与此差异相匹配的任何内容。我怀疑这是一个bug,或者可能是设计的,但是没有很好的文档记录。在

尤其是paste包使用a ^{} configuration file。您可以使用-S禁用此行为以查看其效果。在

$ python -c 'import paste' && echo found
found

$ python -S -c 'import paste' && echo found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named paste

主要问题似乎是paste模块没有__init__.py文件

如果你手动创建它,问题就解决了

相关问题 更多 >

    热门问题