[Twisted-Python] Problems running Twisted
I'm trying to set up a (very simple) web server using Twisted. I'm using this example from the documentation: ============================================================ # teg1.py from twisted.web import server, resource from twisted.internet import reactor class Simple(resource.Resource): isLeaf = True def render(self, request): return "<html>Hello, world!</html>" site = server.Site(Simple()) reactor.listenTCP(8080, site) reactor.run() ============================================================ I've stored this as <teg1.py>. When I run: $ python teg1.py Python complains that it can't import twisted.web: Traceback (most recent call last): File "teg1.py", line 3, in ? from twisted.web import server, resource ImportError: No module named twisted.web I've previously installed Twisted by running: $ python setup.py install which I thought would install all the modules and put them correctly in the PYTHONPATH (tell me if this isn't true). Am I doing somethnig wrong? I feel I have missed something fundamental, but don't know what. Should I rename my file to <teg1.rpy> or something? Do I need to run at the command-line ``mktap'' instead of ``python''? -- Phil Hunt, phil.hunt@tech.mrc.ac.uk
On Fri, Feb 20, 2004 at 09:48:32AM +0000, Phil Hunt wrote:
I'm trying to set up a (very simple) web server using Twisted.
[...]
Python complains that it can't import twisted.web:
Traceback (most recent call last): File "teg1.py", line 3, in ? from twisted.web import server, resource ImportError: No module named twisted.web
I've previously installed Twisted by running:
$ python setup.py install
which I thought would install all the modules and put them correctly in the PYTHONPATH (tell me if this isn't true).
It should... what platform are you on? In fact, it should've told you where it was installing stuff, and you should be able to look at that directory (/usr/lib/python2.3/site-packages on *nix, C:\Python23\Lib\site-packages on Windows, iirc), and see that there is a twisted directory in there.
Am I doing somethnig wrong? I feel I have missed something fundamental, but don't know what. Should I rename my file to <teg1.rpy> or something? Do I need to run at the command-line ``mktap'' instead of ``python''?
No, you're running it the right way -- you can verify that importing is the problem by doing 'python -c "import twisted.web"'. If it's installed in your python's site-packages correctly, it should work, otherwise it should give the error you saw. -Andrew.
On Friday 20 Feb 2004 10:06 am, Andrew Bennetts wrote:
On Fri, Feb 20, 2004 at 09:48:32AM +0000, Phil Hunt wrote:
I'm trying to set up a (very simple) web server using Twisted. Python complains that it can't import twisted.web:
Traceback (most recent call last): File "teg1.py", line 3, in ? from twisted.web import server, resource ImportError: No module named twisted.web
I've previously installed Twisted by running:
$ python setup.py install
which I thought would install all the modules and put them correctly in the PYTHONPATH (tell me if this isn't true).
It should... what platform are you on?
Python 2.3.3 on Mandrake 9.1. On further inspection, it appears the situation is more complicated. When logged in as phunt, I'm running Python 2.3.3 located at /opt/local/bin/python When running as root I'm running Python 2.2.2 located at /usr/bin/python I ran setup.py as root (because phunt didn't have the right priviledges). (Unfortunately I didn't install this box -- lots of stuff is in non-standard places). It appears that <setup.py> has set it up in locations appropriate to root. I've tested this by running <teg1.py> as root and... guess what, it works; when I point my webserver at <http://localhost:8080/> I get the "Hello World" message. -- Phil Hunt, phil.hunt@tech.mrc.ac.uk
On Fri, 2004-02-20 at 22:04, Phil Hunt wrote:
On Friday 20 Feb 2004 10:06 am, Andrew Bennetts wrote:
On Fri, Feb 20, 2004 at 09:48:32AM +0000, Phil Hunt wrote:
I'm trying to set up a (very simple) web server using Twisted. Python complains that it can't import twisted.web:
Traceback (most recent call last): File "teg1.py", line 3, in ? from twisted.web import server, resource ImportError: No module named twisted.web
I've previously installed Twisted by running:
$ python setup.py install
which I thought would install all the modules and put them correctly in the PYTHONPATH (tell me if this isn't true).
It should... what platform are you on?
Python 2.3.3 on Mandrake 9.1.
Mandrake 9.1 didn't ship with Python 2.3.3, so you're either running a version that someone compiled (or otherwise installed covertly), or you're actually running cooker. In the latter case, there's rpms of Twisted available to you. Try this: http://mirror.aarnet.edu.au/pub/mandrake-devel/cooker/i586/Mandrake/RPMS2/py... (or a mirror near you). However, I mirror the sentiments later in this thread about filing a bug. HTH, James.
Phil Hunt wrote:
I'm trying to set up a (very simple) web server using Twisted. I'm using this example from the documentation:
...
$ python teg1.py
Python complains that it can't import twisted.web: ... I've previously installed Twisted by running:
$ python setup.py install
which I thought would install all the modules and put them correctly in the PYTHONPATH (tell me if this isn't true).
It doesn't actually modify PYTHONPATH, it (hopefully) puts Twisted in a directory that's already in sys.path. Which version of python did you run setup.py? Ensure /usr/lib/pythonX.X/site-packages/twisted exists. Make sure you're running your script with the same version.
Am I doing somethnig wrong? I feel I have missed something fundamental, but don't know what. Should I rename my file to <teg1.rpy> or something? Do I need to run at the command-line ``mktap'' instead of ``python''?
No, the way you're doing it is fine. -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com/
Phil Hunt [Fri, Feb 20, 2004 at 09:48:32AM +0000]:
from twisted.web import server, resource [...] Traceback (most recent call last): File "teg1.py", line 3, in ? from twisted.web import server, resource ImportError: No module named twisted.web
I've previously installed Twisted by running:
$ python setup.py install
Perhaps you should try to reinstall Twisted, or check how the above line ("from twisted.web ...") works in the interactive mode.
What exactly is the difference between running "python setup.py" and just copying the twisted/ directory to site-packages/ directory? I tried installing Twisted on old server which has Python 2.2 - the first method didn't work, the second did. -- Frantisek Fuka (yes, that IS my real name) (and it's pronounced "Fran-tjee-shek Foo-kah") ---------------------------------------------------- My E-mail: fuka@fuxoft.cz My Homepage: http://www.fuxoft.cz My ICQ: 2745855
Frantisek Fuka [Fri, Feb 20, 2004 at 11:40:09AM +0100]:
What exactly is the difference between running "python setup.py" and just copying the twisted/ directory to site-packages/ directory? I tried installing Twisted on old server which has Python 2.2 - the first method didn't work, the second did.
What exactly didn't work in the first method? About setup.py, read at http://python.org/doc/2.3.3/lib/module-distutils.html
Michal Pasternak wrote:
Frantisek Fuka [Fri, Feb 20, 2004 at 11:40:09AM +0100]:
What exactly is the difference between running "python setup.py" and just copying the twisted/ directory to site-packages/ directory? I tried installing Twisted on old server which has Python 2.2 - the first method didn't work, the second did.
What exactly didn't work in the first method?
It halted on exception about some directory not found. Because the directory name contained some variation of "python2.3" string, I presumed that the problem is with the server only having python2.2 installed. -- Frantisek Fuka (yes, that IS my real name) (and it's pronounced "Fran-tjee-shek Foo-kah") ---------------------------------------------------- My E-mail: fuka@fuxoft.cz My Homepage: http://www.fuxoft.cz My ICQ: 2745855
Frantisek Fuka [Fri, Feb 20, 2004 at 12:25:38PM +0100]:
Michal Pasternak wrote:
Frantisek Fuka [Fri, Feb 20, 2004 at 11:40:09AM +0100]:
What exactly is the difference between running "python setup.py" and just copying the twisted/ directory to site-packages/ directory? I tried installing Twisted on old server which has Python 2.2 - the first method didn't work, the second did.
What exactly didn't work in the first method?
It halted on exception about some directory not found. Because the directory name contained some variation of "python2.3" string, I presumed that the problem is with the server only having python2.2 installed.
Distutils are a part of Python distribution. When you run interpreter and "import distutils", they already know, what version of Py you are running, so if you ran Python 2.2, missing 2.3 is not a real problem. You didn't provide exact error message, which would of course help to identify the problem; using my telepathic powers, I bet you're running Debian without the package for distutils installed. AFAIR, it is included in pythonX.X-dev.
I encountered the similar problem before with rpm-based distribution. Just grab the python-devel-xxx.rpm and install. HTH -- Yun
You didn't provide exact error message, which would of course help to identify the problem; using my telepathic powers, I bet you're running Debian without the package for distutils installed. AFAIR, it is included in pythonX.X-dev.
Yun Mao wrote:
I encountered the similar problem before with rpm-based distribution. Just grab the python-devel-xxx.rpm and install.
Thanks. But the current question is: I already "installed" twisted by simply copying the twisted/ subdirectory into site-packages/ and everything seems to run OK. "If it ain't broke..." Or is it broken? -- Frantisek Fuka (yes, that IS my real name) (and it's pronounced "Fran-tjee-shek Foo-kah") ---------------------------------------------------- My E-mail: fuka@fuxoft.cz My Homepage: http://www.fuxoft.cz My ICQ: 2745855
I guess the pure python part (which is almost the whole part?) would be fine. However, you probably do not have those handy script installed in the $PATH, such as twistd, mktap, etc. -- Yun On Fri, 20 Feb 2004, Frantisek Fuka wrote:
Yun Mao wrote:
I encountered the similar problem before with rpm-based distribution. Just grab the python-devel-xxx.rpm and install.
Thanks. But the current question is: I already "installed" twisted by simply copying the twisted/ subdirectory into site-packages/ and everything seems to run OK. "If it ain't broke..."
Or is it broken?
Yun Mao wrote:
I guess the pure python part (which is almost the whole part?) would be fine. However, you probably do not have those handy script installed in the $PATH, such as twistd, mktap, etc.
That's not a problem, I am just importing Twisted modules into my Python application. Am I correct in thinking that if I installed it "correctly" (using setup.py), Twisted would compile some binaries and then be faster/more stable etc...? -- Frantisek Fuka (yes, that IS my real name) (and it's pronounced "Fran-tjee-shek Foo-kah") ---------------------------------------------------- My E-mail: fuka@fuxoft.cz My Homepage: http://www.fuxoft.cz My ICQ: 2745855
Frantisek Fuka wrote:
Yun Mao wrote:
I guess the pure python part (which is almost the whole part?) would be fine. However, you probably do not have those handy script installed in the $PATH, such as twistd, mktap, etc.
That's not a problem, I am just importing Twisted modules into my Python application.
Am I correct in thinking that if I installed it "correctly" (using setup.py), Twisted would compile some binaries and then be faster/more stable etc...?
There are a number of optional C extensions. So, perhaps, depending on what parts you're using, it could be faster. They're written in C, though, so generally I would assume that the potential for *in*stability is higher when you use them, but that's not a comment about any of our C extensions specifically. ;-) So, you get C extensions and bin scripts in $prefix when you use setup.py. Nothing critical. However! Before you forget this topic: you said you had a problem with running setup.py, so a real bug report would be very much appreciated. -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com/
Christopher Armstrong wrote:
However! Before you forget this topic: you said you had a problem with running setup.py, so a real bug report would be very much appreciated.
I must say the offending server is in VERY bad shape installation-wise and I plan to completely re-install it when my application is ready to deploy. There are missing libraries, partly-installed packages etc... I "inherited" this server, everything was installed by someone else and I must confess I am not very much of Linux guru. Because of this, it's perfectly feasible that it wasn't Twisted's error and even in the case it was, I am not brave enough to try to re-install twisted now, when I have it running and I can test the application I am developing... -- Frantisek Fuka (yes, that IS my real name) (and it's pronounced "Fran-tjee-shek Foo-kah") ---------------------------------------------------- My E-mail: fuka@fuxoft.cz My Homepage: http://www.fuxoft.cz My ICQ: 2745855
participants (7)
-
Andrew Bennetts
-
Christopher Armstrong
-
Frantisek Fuka
-
James Gregory
-
Michal Pasternak
-
Phil Hunt
-
Yun Mao