Question

I am trying to execute a python program that uses twisted web, but for some reason it cannot import http. I am new to this and I am not really familiar enough to solve this issue. I have done some googling and I can't really find anything that seems relevant to this particular issue, only some vaguely similar things that don't seem to resolve the issue.

Traceback (most recent call last):
  File "./test.py", line 27, in <module>
    from twisted.web import http
ImportError: cannot import name http

OS: CentOS 5.9 Python version: 2.7.5

$ yum list installed | grep twisted
python-twisted-core.i386              2.5.0-4.el5                      installed
python-twisted-web.i386               0.7.0-1.el5                      installed

Here is what the import looks like:

 from twisted.web import http
Was it helpful?

Solution

What I would do is ensure everything is set up properly by not relying on any system-wide, potentially out-of-date installations of Twisted:

$ sudo pip install virtualenv
...
$ cd your/project/dir
$ virtualenv venv
...
$ . venv/bin/activate
$ pip install Twisted
...
$ python -c "import twisted; print twisted.version"
... should print: Version('twisted', 13, 1, 0)
$ python -c "import twisted.web.http"
... should work without ImportError
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top