?
Solved

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

Posted on 2007-04-06
6
Medium Priority
?
1,439 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
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 

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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

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…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

764 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