2

First of all, I need to run twisted application on my server but what I get is this error

File "server2.py", line 1, in <module>
from twisted.internet.protocol import Factory, Protocol
File "/usr/lib64/python2.6/site-packages/Twisted-15.0.0-py2.6-linux-x86_64.egg/twisted/__init__.py", line 53, in <module>
_checkRequirements()
File "/usr/lib64/python2.6/site-packages/Twisted-15.0.0-py2.6-linux-x86_64.egg/twisted/__init__.py", line 51, in _checkRequirements
raise ImportError(required + ".")
ImportError: Twisted requires zope.interface 3.6.0 or later.

So, this leads me to installed zope.interface. After running setup.py in zope.interface-4.1.2, I see this

Finished processing dependencies for zope.interface==4.1.2

I think I've updated it but when I run my twisted app, the same error appeared. Please help me.

maou
  • 23
  • 5

2 Answers2

1

Which linux distro/AMI are you using? did you check if you have multiple python versions installed? maybe zope.interface requires c-binding library and you better of installing this package from apt-get/yum?

Shimon Tolts
  • 1,602
  • 14
  • 15
  • I'm not sure about multiple Python version but when I checked it using python -V command, it showed me only one version. And about c-binding library, could you tell the name of that package. – maou Feb 14 '15 at 11:55
  • did you try to re-install twisted after installing the zope.interface lib? – Shimon Tolts Feb 14 '15 at 12:05
0

on ec2

If you see this message it means that zope.interface is available but has raised some reason why it might not work.

The code that imports zope.interface is shown below

# Don't allow the user to run with a version of zope.interface we don't
# support.
required = "Twisted requires zope.interface %s or later" % (required,)
try:
    from zope import interface
except ImportError:
    # It isn't installed.
    raise ImportError(required + ": no module named zope.interface.")
except:
    # It is installed but not compatible with this version of Python.
    raise ImportError(required + ".")

reinstalling the same version of zope.interface will probably not solve the issue but might be worth a shot. uninstall zope.interface first and then make sure there's no zope.interface stuff in you python site-packages directory before installing with pip install zope.interface.

The asker could try an alternative version of zope.interface but I think the issue is more likely related to the way python is installed on the system or that twisted is not installed correctly. You could try uninstalling pip uninstall twisted and then reinstalling twisted pip install twisted

likely solution

The easiest way to resolve the problem would be to run the application within a virtual environment and control which packages are installed. see the documentation here: https://virtualenv.pypa.io/en/latest/

for example you could install venv using pip and then install twisted into it

pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install twisted
deactivate

you can try a different version of python than the system default with something like this

virtualenv -p /usr/bin/python2.7 venv

AWS Lambda

I ran into a similar issue when trying to run twisted on aws lambda.

I found that zope.interface could not be imported when installed using pip in a venv. It looked like some stuff was missing which meant it couldn't be imported normally as a module in my zip package but would probably work in the venv. removing it from site packages and replacing it with the source files solved my issue.

https://pypi.python.org/pypi/zope.interface/4.1.3#downloads

The current version at this time is zope.interface-4.1.3.tar.gz

bob
  • 681
  • 5
  • 17