Solved

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

Posted on 2007-04-06
6
1,430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
RichieHindle earned 250 total points
ID: 18865166
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
ID: 18865440
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
ID: 18865530
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
Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 

Author Comment

by:Randall-B
ID: 18865587
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
ID: 18866205
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
ID: 18866256
You are invited to comment on my related question at:
http:/Q_22496947.html  .  Thanks.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

739 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