Solved

Python on WAMP: Error When Trying to Run .py Script

Posted on 2007-04-06
6
1,417 Views
Last Modified: 2012-05-05
I'm trying to test a Python script on WAMP.  I have a working WAMP installation, and followed instructions to add Python (on this page: http://www.mplstutorial.com/wamp_python/python_wamp.html ), except that everything is on the D: drive.  I also restarted the WAMP Server.  
      This error appears when I try to run a page with the .py extension:

  Mod_python error: "PythonHandler default"

  Traceback (most recent call last):

  File "D:\Python24\Lib\site-packages\mod_python\apache.py", line 287, in HandlerDispatch
    log=debug)

  File "D:\Python24\Lib\site-packages\mod_python\apache.py", line 461, in import_module
    f, p, d = imp.find_module(parts[i], path)

   ImportError: No module named default
0
Comment
Question by:Randall-B
  • 4
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
RichieHindle earned 250 total points
Comment Utility
Saying "PythonHandler default" means "I want all requests to be handled by default.py".  If you have no default.py, you'll get that ImportError.

If you've taken the exact httpd.conf from that "Running Python with WAMP5" page, it's configured for requests for "index.py" and "xa.py" to be handled by those files, and for all other requests to be handled by default.py.  (See the section <Directory "C:/wamp/www/"> in httpd.conf)

If you want a URL like "http://myserver/mymodule.py" to run mymodule.py, you need to use mod_python's CGI Handler: "PythonHandler mod_python.cgihandler"

See http://www.modpython.org/live/current/doc-html/hand-cgi.html for the CGI Handler documentation.

0
 

Author Comment

by:Randall-B
Comment Utility
RichieHindle,
   Thanks. I'm just trying to run a script like HelloWorld.py in my www directory.  

Then I put the .htaccess file in the   www  directory, with:
     SetHandler mod_python
     PythonHandler mod_python.cgihandler
as recommended on the modpython page, then restarted the server.
    The error messages went away.  But now only a blank screen appears; it does not print anything to the browser.  (However, the HelloWorld.py script *does* run from the command line.)

I tried the bang line as:
     #!/usr/bin/python
and also as:
    #!D:\Python24
but either way, the script will not run properly when called from the url like
     http://localhost/HelloWorld.py

 What could be wrong?
0
 
LVL 14

Assisted Solution

by:RichieHindle
RichieHindle earned 250 total points
Comment Utility
The shebang line should probably be:

#!D:\Python24\python.exe

but that shouldn't matter for mod_python.

Try this HelloWorld.py:

#!D:\Python24\python.exe
print "Content-Type: text/plain\n\n"
print "Hello, World!\n"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Randall-B
Comment Utility
Yes, that worked, even without the   .exe  
  Looks like the problem was, I forgot the header
         print "Content-Type: text/plain\n\n"

So, overall, the problems were the   .htaccess  statements and the content-type header.

It seems to be working now. Thanks!
0
 

Author Comment

by:Randall-B
Comment Utility
RichieHindle,
   If you happen to see this, even though it's PAQ'd, I discovered an unintended problem with the .htaccess file:  when it is in my   www  directory, Python files will run, but html files treated as if not even there.  So I had to delete or comment-out the .htaccess statements just to be able to view  html  files on localhost again.
    Maybe the statements in .htaccess can be modified to allow both kinds of files to work simultaneously?  Thanks.
0
 

Author Comment

by:Randall-B
Comment Utility
You are invited to comment on my related question at:
http:/Q_22496947.html  .  Thanks.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now