Help us understand the problem. What is going on with this article?

ImportError: No module named と言われた時の対応方法

More than 5 years have passed since last update.
import pyramid.config

をすると、ImportError: No module named interfaceと言われるようになった。
easy_install zope.interfaceしても解決しないので原因を調査してみた。

In [1]: import zope.interface
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-bc61dfc4e3ea> in <module>()
----> 1 import zope.interface

ImportError: No module named interface

path確認

ipython
In [1]: import sys
In [2]: sys.path
Out[2]: 
['',
 '/usr/bin',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/IPython/extensions']
  • importは上から順に探して、発見したらそこで終了。

zopeパッケージの格納場所を探す

$ locate zope | more
...
/usr/local/lib/python2.7/dist-packages/zope
...
/usr/lib/python2.7/dist-packages/zope.interface-4.0.5.egg-info
...
/usr/share/pyshared/zope.interface-4.0.5.egg-info
...
$ ls /usr/local/lib/python2.7/dist-packages/zope
deprecation

このパッケージが邪魔してるので削除。

$ sudo rm -r /usr/local/lib/python2.7/dist-packages/zope*
$ sudo easy_install zope.interface
$ sudo easy_install zope.deprecation
import pyramid.config

成功しました。

  • どのファイルがimportに使われたかは、helpを使うとわかります。
import zope.interface
help(zope.interface)
...
FILE
    /usr/lib/python2.7/dist-packages/zope/interface/__init__.py
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away