简体   繁体   中英

ImportError: No module named zope.interface but modules found

I am pretty new to python and I am trying to import a module while using a virtualenv.

When I import the module I get:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition   4.0.6\helpers\pydev\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named zope.interface

I am trying to import the zope.interface module with line:

import zope.interface

I have double check that this module is installed by calling “pip freeze”. I have also found the location of the module in my virtualEnv site-packages directoy. The path to the modules is:

virName\Lib\site-packages\zope\interface

inside this directory I can see the __init__.py file.

It was my understanding that the presence of the __init__.py file alone would make this a valid module?

I double checked the search path for my module by doing sys.path and It did contain the directory “virName\\Lib\\site-packages\\”

So my question is this. Why is python saying it can't find the module?

What else do I need to check for?

I have also tried find the modules using:

imp.find_module('zope.interface')

but i get:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
ImportError: No module named zope.interface

Try

pip install zope.interface

from a command line prompt from a directory with the pip.exe, such as

C:\anaconda3\Scripts>pip install zope.interface

I had the same issue and it got resolved after installing as above

I've had this same problem. To expound a bit, PyCharm uses iPython if you have it installed, and iPython uses zope.interface also. I'm on a Mac developing a Pyramid project (which uses zope.inerface ) and see this behavior:

Python in system Terminal

$ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope.interface
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named interface
>>> 

iPython in system Terminal

$ ipython
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
Type "copyright", "credits" or "license" for more information.

IPython 3.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import zope.interface

In [2]: 

Note that it imports without an error - and it's using the same python interpreter as the 1st example!

Python Console in PyCharm According to PyCharm docs, this uses iPython, and we see this is try from the startup output:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 -u /Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py 63304 63305
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
Type "copyright", "credits" or "license" for more information.

IPython 3.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
PyDev console: using IPython 3.1.0

import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['/Users/someone/PycharmProjects/SMS_PUB_API'])

Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
In[2]: import zope.interface
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-bc61dfc4e3ea>", line 1, in <module>
    import zope.interface
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: No module named interface
In[3]: 

Note that if I use PyCharm's Terminal feature to then use the system Python and iPython consoles, i get the same results as the 1st 2 examples above.

Running Pyramid from PyCharm The odd part is, if I run my Pyramid project from within PyCharm (Which uses zope.interfaces) using the same project interpreter as the above examples , it starts up just fine

It's tempting to think it's an issue with the zope.interface module being named with a dot in it - that's normally reserved python terminology to express a path. However, other zope.* modules import just fine. I went into PyCharm's Project Interpreter settings and noticed I was using zope.interface 4.1.1 and that 4.1.2 is out. After updating (in pycharm), it works fine - i can now import zope.interfaces .

Note, this also happened in the normal Mac Terminal. Before writing this post, i could not import it with iPython. After upgrading iPython, it worked in the terminal (my 2nd example above).

Hope this helps!

I met the same issue, failed to import zope when installed with exe. Because the __init__.py file is missing under zope folder.

easy_install zope.interface-3.8.0.win-amd64-py2.7.exe

It works when install with egg like this

easy_install zope.interface-3.8.0-py2.7-win-amd64.egg

Download the egg from enter link description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM