[Twisted-web] twistd and web2 weirdness

Phil Christensen phil at bubblehouse.org
Tue Jul 24 11:35:34 EDT 2007


I'm totally confounded on this one. For some reason, when using  
twistd, web2 cannot be found by the interpreter. (I'm running Twisted  
SVN HEAD on pythonmac's Python 2.4 on Mac OS X.)

For example, I've got the following code in a file called twisted.py


     from twisted.web2 import server, channel, static, wsgi

     def handler(env, start_response):
     	pass

     # This part gets run when you run this file via: "twistd -noy  
modu/web/twisted.py"
     root = wsgi.WSGIResource(handler)
     site = server.Site(root)

     # Start up the server
     from twisted.application import service, strports
     application = service.Application("web2")
     s = strports.service('tcp:8888', channel.HTTPFactory(site))
     s.setServiceParent(application)


When running it (with twistd -noy twisted.py), I get:


     Traceback (most recent call last):
       File "/Library/Frameworks/Python.framework/Versions/Current/ 
bin/twistd", line 20, in ?
         from twisted.scripts.twistd import run
       File "/Users/phil/Desktop/twisted.py", line 1, in ?
         from twisted.web2 import server, channel, static, wsgi
     ImportError: No module named web2


This is a standard Twisted installation using `python setup.py  
install`, and web2 is clearly in my site-packages directory:


     optimus:~ phil$ ls -la /Library/Frameworks/Python.framework/ 
Versions/2.4/lib/python2.4/site-packages/twisted/web2
     total 1272
     drwxr-xr-x   54 root  admin   1836 Jul 24 10:54 .
     drwxr-xr-x   36 root  admin   1224 Jul 24 10:54 ..
     -rw-r--r--    1 root  admin    254 Jun 29  2006 __init__.py
     -rw-r--r--    1 root  admin    371 Jul 24 10:54 __init__.pyc
     ...
     ...


Even stranger is that twistd doesn't seem to have any problems  
finding/loading the web2 plugin


     optimus:~ phil$ twistd
     Usage: twistd [options]
     ...
     ...
     ...
     Commands:
         web2             An HTTP/1.1 web server that can serve from  
a filesystem or
                          application resource.
     ...
     ...
     ...


And when running the exact interpreter path specified in twistd,  
there are no problems either:


     optimus:~ phil$ which twistd
     /Library/Frameworks/Python.framework/Versions/Current/bin/twistd

     optimus:~ phil$ head -n 1 /Library/Frameworks/Python.framework/ 
Versions/Current/bin/twistd
     #!/Library/Frameworks/Python.framework/Versions/2.4/Resources/ 
Python.app/Contents/MacOS/Python

     optimus:~ phil$ /Library/Frameworks/Python.framework/Versions/ 
2.4/Resources/Python.app/Contents/MacOS/Python
     Python 2.4.3 (#1, Apr  7 2006, 10:54:33)
     [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
     Type "help", "copyright", "credits" or "license" for more  
information.
     >>> from twisted.web2 import server
     >>>


I had this same issue on my other development machine, also a Mac,  
but I assumed it was some kind of configuration issue with that  
machine in particular.

Has anyone had a similar experience? Any help in this matter would be  
appreciated.

-phil



More information about the Twisted-web mailing list