5

I am installing a project in virtual environment. I am getting error

from zope.interface.registry import Components
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named registry

Version of this module as 4.0.5

>>> import pkg_resources
>>> pkg_resources.get_distribution("zope.interface").version
'4.0.5'

I tried the same on my machine (not virtual env),

>>> import pkg_resources
>>> pkg_resources.get_distribution("zope.interface").version
'4.0.1'
>>> from zope.interface.registry import Components

Here from zope.interface.registry import Components didn't give any error. According to this

QUOTE: 3.8.0 (2011-09-22) 
New module zope.interface.registry. This is code moved from 
zope.component.registry which implements a basic nonperistent component registry 
as zope.interface.registry.Components.

, it should not give any error. Any suggestion what I'm missing here or how to solve this error ?

Netro
  • 7,119
  • 6
  • 40
  • 58
  • I can't reproduce this is a fresh virtualenv. Can you see the `registry.py` file in `ls lib/python*/site-packages/zope/interface`? – Martijn Pieters Mar 25 '13 at 08:41
  • I had installed zope on system before installing project in virtual env. I checked the path of imported module (zope.interface) in my virtual and non-virtual env. Virtual `'/usr/lib/python2.7/dist-packages/zope/interface/__init__.pyc'` and non-virtual is `/usr/local/lib/python2.7/dist-packages/zope.interface-4.0.1-py2.7-linux-x86_64.egg/zope/interface/__init__.pyc`. Only under non-virtual location I can find `registry.py` – Netro Mar 25 '13 at 10:00
  • What does the `ls` command in the virtual env tell you is there? What does `import zope.interface;print(zope.interface.__file__)` say? – Martijn Pieters Mar 25 '13 at 10:02
  • hi check again.. I have updated the comment – Netro Mar 25 '13 at 10:02
  • Ah, you are importing the system interfaces package, *not* one installed in a virtual environment. Are you certain you installed it? Do you run your virtualenv *without* system packages? – Martijn Pieters Mar 25 '13 at 10:04
  • I'm not sure. I just ran command `virtualenv folder-name` – Netro Mar 25 '13 at 10:10
  • Right, this is Ubuntu (or Debian perhaps?) and it does fun things with `dist-packages` that I am not 100% certain about how it interacts with virtualenv. What it comes down to here is that the system-installed `zope.interface` is being used, *not* anything you installed in your virtualenv. Current versions of `virtualenv` make the `--no-site-packages` option the default, but you may want to use that option explicitly if your `virtualenv` is older (check `virtualenv --help` to see if the option is the default). I just *don't know* if `dist-packages` is supposed to be excluded or not. – Martijn Pieters Mar 25 '13 at 10:24

2 Answers2

4

I had similar error - I tryed to create new virtual env without site-packages. It creates all fine. But my ubuntu has already installed zope.interface for own use, so it did not want to install it additional to my venv.

This collision cause my venv to throw error in simple test app under mod_wsgi:

     from zope.interface.registry import Components
ImportError: No module named registry

So I trying to remove zope.interface from base python. But unistall command not removed it(i found in google, that it is known problem).

Than i found solution: I just switched to my venv and give command for "upgrading" zope.interface from there:

(env)user@ubuntu:~/env$ sudo pip install --upgrade zope.interface

After this my problem with zope.interface dissmiss.

Your problem is similar, so my solution could help. Anyway this answer is very useful for ubuntu desktop users.

msangel
  • 9,895
  • 3
  • 50
  • 69
0

Just in case anyone is still having same issue, try this:

apt remove --purge certbot
apt autoremove
apt clean
apt install certbot -u

Tested on 'Debian 11 (bullseye)' & 'Ubuntu 22.04'

Janib Soomro
  • 446
  • 6
  • 12