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
Hi Phil, On Tue, 24 Jul 2007 10:35:34 -0500, Phil Christensen <phil@bubblehouse.org> wrote:
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
Bzzzt! Owie! Don't do that. The topmost package in the twisted codebase is named "twisted". You've shadowed that package with a module of your own. Try renaming your file to something else, and I'll bet things start working for you. Hope this helps, L. Daniel Burr
On Jul 24, 2007, at 12:18 PM, L. Daniel Burr wrote:
Hi Phil,
On Tue, 24 Jul 2007 10:35:34 -0500, Phil Christensen <phil@bubblehouse.org> wrote:
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
Bzzzt! Owie! Don't do that. The topmost package in the twisted codebase is named "twisted". You've shadowed that package with a module of your own.
Try renaming your file to something else, and I'll bet things start working for you.
Thanks for the fast reply, but unfortunately that's not the problem. 'twisted.py' was just the example minimum file i was using to describe the problem, although I clearly should have used something else. Also, I'm pretty sure twistd's -y param simply loads this as a file (hence the ability to name it with a .tac file). My actual app file is called 'twserver.py'. I did try renaming the example file I created before sending my previous email, but alas, no success. -phil
On Jul 24, 2007, at 1:08 PM, Phil Christensen wrote:
On Jul 24, 2007, at 12:18 PM, L. Daniel Burr wrote:
Bzzzt! Owie! Don't do that. The topmost package in the twisted codebase is named "twisted". You've shadowed that package with a module of your own.
Try renaming your file to something else, and I'll bet things start working for you.
Thanks for the fast reply, but unfortunately that's not the problem. 'twisted.py' was just the example minimum file i was using to describe the problem, although I clearly should have used something else.
Also, I'm pretty sure twistd's -y param simply loads this as a file (hence the ability to name it with a .tac file).
Ah, but you meant that if the current directory is in my path, this would clobber the twisted package. Sorry about that. Fortunately, it's neither named 'twisted' or in my path ;-). -phil
On Jul 24, 2007, at 1:12 PM, Phil Christensen wrote:
On Jul 24, 2007, at 1:08 PM, Phil Christensen wrote:
On Jul 24, 2007, at 12:18 PM, L. Daniel Burr wrote:
Bzzzt! Owie! Don't do that. The topmost package in the twisted codebase is named "twisted". You've shadowed that package with a module of your own.
Try renaming your file to something else, and I'll bet things start working for you.
Thanks for the fast reply, but unfortunately that's not the problem. 'twisted.py' was just the example minimum file i was using to describe the problem, although I clearly should have used something else.
Also, I'm pretty sure twistd's -y param simply loads this as a file (hence the ability to name it with a .tac file).
Ah, but you meant that if the current directory is in my path, this would clobber the twisted package. Sorry about that. Fortunately, it's neither named 'twisted' or in my path ;-).
Ah, but a leftover twisted.pyc file is! Thanks so much, Daniel! Strange things are no longer afoot at the Circle K. -phil
Hi Phil, On Tue, 24 Jul 2007 12:15:17 -0500, Phil Christensen <phil@bubblehouse.org> wrote:
On Jul 24, 2007, at 12:18 PM, L. Daniel Burr wrote:
Bzzzt! Owie! Don't do that. The topmost package in the twisted codebase is named "twisted". You've shadowed that package with a module of your own.
Try renaming your file to something else, and I'll bet things start working for you.
[some further explanation of the problem, investigations, etc.]
Ah, but a leftover twisted.pyc file is!
Thanks so much, Daniel! Strange things are no longer afoot at the Circle K.
You're welcome. I think everyone has been bitten by some variant of this problem at one time or another, and it certainly does cause some head-scratching the first time you experience it. L. Daniel Burr
participants (2)
-
L. Daniel Burr
-
Phil Christensen