Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-04-06
6
Medium Priority
?
1,447 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 1000 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 1000 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
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 lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

610 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