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
I've had this same problem. To expound a bit, PyCharm uses iPython if you have it installed, and iPython uses
zope.interfacealso. I'm on a Mac developing a Pyramid project (which useszope.inerface) and see this behavior:Python in system Terminal
iPython in system Terminal
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:
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.interfacemodule being named with a dot in it - that's normally reserved python terminology to express a path. However, otherzope.*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 importzope.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!