Welcome Guest. Please Login or Register  


You are here: Index > AMPPS > General Support > Topic : I can't run python scripts

1


Threaded Mode | Print  

 I can't run python scripts (25 Replies, Read 41137 times)
muotaz
Group: Member
Post Group: Newbie
Posts: 1
Status:
Hello All;

I am a bit new to AMPPS and Python Development.
I tried to run Python scripts on AMPPS with no luck.
Any help or hints are highly appreciated.

IP: --   

I can't run python scripts
tidus
Group: Member
Post Group: Super Member
Posts: 1121
Status:
Hi,

For running python scripts you must first get familiar with mod_wsgi. Here is the tutorial to run the python scripts using mod_wsgi.

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack
IP: --   

I can't run python scripts
memzxi
Group: Member
Post Group: Newbie
Posts: 8
Status:
Hi. Another newbie here. I thank you for your work creating the product and giving it for free, but after that much work, is it that hard to make Python run by default ?

If I want to run php, I put test.php file in www directory and it works fine. I put test.py and it shows unprocessed source code, the same as it would if I opened it in a browser without AIMPS installed.

Can you just say which file to put where in order for it to work ?

I read quick configuration guide that you posted a link to, but it doesn't seem to help properly.

What I did is put the code below in C:\Program Files\Ampps\apache\conf\httpd.conf in line 634 after << # Python
Include "C:/Program Files/Ampps/python/python.conf" >>

Quote
<VirtualHost *:80>

    ServerName localhost
    ServerAlias 127.0.0.1
    ServerAdmin webmaster@example.com

    DocumentRoot /usr/local/www/documents

    <Directory /usr/local/www/documents>
    Order allow,deny
    Allow from all
    </Directory>

    WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi

    <Directory /usr/local/www/wsgi-scripts>
    Order allow,deny
    Allow from all
    </Directory>

</VirtualHost>


After that, I created the file

C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi and put the code below in it. the code is from that "quick" configuration guide

Quote

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]


Then I restarted apache, tried to access
http://localhost/documents/test.py
http://localhost/test.py
http://localhost/wsgi-scripts/test.py

none worked, help ? ( AMPPS installation is fresh, nothing modified )
IP: --   

I can't run python scripts
tidus
Group: Member
Post Group: Super Member
Posts: 1121
Status:
Quote From : memzxi December 26, 2012, 8:04 pm
Hi. Another newbie here. I thank you for your work creating the product and giving it for free, but after that much work, is it that hard to make Python run by default ?

If I want to run php, I put test.php file in www directory and it works fine. I put test.py and it shows unprocessed source code, the same as it would if I opened it in a browser without AIMPS installed.

Can you just say which file to put where in order for it to work ?

I read quick configuration guide that you posted a link to, but it doesn't seem to help properly.

What I did is put the code below in C:\Program Files\Ampps\apache\conf\httpd.conf in line 634 after << # Python
Include "C:/Program Files/Ampps/python/python.conf" >>

Quote
<VirtualHost *:80>

    ServerName localhost
    ServerAlias 127.0.0.1
    ServerAdmin webmaster@example.com

    DocumentRoot /usr/local/www/documents

    <Directory /usr/local/www/documents>
    Order allow,deny
    Allow from all
    </Directory>

    WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi

    <Directory /usr/local/www/wsgi-scripts>
    Order allow,deny
    Allow from all
    </Directory>

</VirtualHost>


After that, I created the file

C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi and put the code below in it. the code is from that "quick" configuration guide

Quote

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]


Then I restarted apache, tried to access
http://localhost/documents/test.py
http://localhost/test.py
http://localhost/wsgi-scripts/test.py

none worked, help ? ( AMPPS installation is fresh, nothing modified )


Hi,

Your VirtualHost is wrongly configured, you will have to change(take care of) the paths.
i.e change all
Code
/usr/local/www/documents
to
Code
"C:\Program Files\Ampps\www\wsgi-scripts"
(Yes, with double quotes).

Change 
Code
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
to
Code
WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi"


And Remove This Tag
Code
<Directory /usr/local/www/wsgi-scripts>
    Order allow,deny
    Allow from all
    </Directory>


Restart Apache.

And try accessing http://localhost/myapp

Let us know the output.

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack
IP: --   

I can't run python scripts
memzxi
Group: Member
Post Group: Newbie
Posts: 8
Status:
Didn't work. Ended up with this code in C:\Program Files\Ampps\apache\conf\httpd.conf

Quote

<VirtualHost *:80>

    ServerName localhost
    ServerAlias 127.0.0.1
    ServerAdmin webmaster@example.com

    DocumentRoot "C:\Program Files\Ampps\www\wsgi-scripts"

    <Directory "C:\Program Files\Ampps\www\wsgi-scripts">
    Order allow,deny
    Allow from all
    </Directory>

    WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi"

</VirtualHost>


What I get is the same as I put in code editor
Quote

#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello World from PythonStandard Hello World from a Python"

IP: --   

I can't run python scripts
tidus
Group: Member
Post Group: Super Member
Posts: 1121
Status:
Quote From : memzxi December 26, 2012, 8:04 pm

After that, I created the file

C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi and put the code below in it. the code is from that "quick" configuration guide

Quote

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]



Hi,

The contents were right before which you copied from "quick" configuration guide.

Edited by tidus : December 27, 2012, 1:23 pm

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack
IP: --   

I can't run python scripts
memzxi
Group: Member
Post Group: Newbie
Posts: 8
Status:
Didn't understand what you meant here.

This is my test.py which is in C:\Program Files\Ampps\www\myapp\test.py and I get the same text if open the browser at localhost/myapp/test.py
Quote
#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello World from PythonStandard Hello World from a Python"



Content of C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi is the same, I didn't changed it after first creating the file and pasting the code
Quote
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

IP: --   

I can't run python scripts
tidus
Group: Member
Post Group: Super Member
Posts: 1121
Status:
Quote From : memzxi December 27, 2012, 1:57 pm
Didn't understand what you meant here.

This is my test.py which is in C:\Program Files\Ampps\www\myapp\test.py and I get the same text if open the browser at localhost/myapp/test.py
Quote
#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello World from PythonStandard Hello World from a Python"



Content of C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi is the same, I didn't changed it after first creating the file and pasting the code
Quote
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]



What is the output of http://localhost/myapp ?

BTW Python scripts doesn't work like PHP here.

In virtualhost when we configure
Code
WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi"
http://localhost/myapp becomes the alias to myapp.wsgi. Hope you get it now. :)

Also the below code won't work... here you here using directly the CGI(not mod_wsgi). :)

Instead of below code,
Code
#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello World from PythonStandard Hello World from a Python"


write the following code.
Code
#!"C:\Program Files\Ampps\python\python.exe"
print "Content-type: text/html\n\n"
print "Hello World from PythonStandard Hello World from a Python"


Before you run test.py, Go to AMPPS Application -> Apache Tab -> Configuration Tab. Find Line
Code
AddHandler cgi-script .cgi .pl
change it to
Code
AddHandler cgi-script .cgi .pl .py
Save the File. Restart Apache.
Copy test.py and paste it to C:\Program Files\Ampps\www\cgi-bin\test.py and
access http://localhost/cgi-bin/test.py

Edited by tidus : December 27, 2012, 2:23 pm

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack
IP: --   

I can't run python scripts
memzxi
Group: Member
Post Group: Newbie
Posts: 8
Status:
I installed AMPPS freshly just in case.

1. In folder C:\Program Files\Ampps\www created new folder "wsgi-scripts"
2. in newly created folder C:\Program Files\Ampps\www\wsgi-scripts created file "myapp.wsgi" contents below

Code

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]


3. Opened the file C:\Program Files\Ampps\apache\conf\httpd.conf
4. In file C:\Program Files\Ampps\apache\conf\httpd.conf line 637 pasted the code

Code

<VirtualHost *:80>
    ServerName localhost
    ServerAlias 127.0.0.1
    ServerAdmin webmaster@example.com

    DocumentRoot "C:\Program Files\Ampps\www\wsgi-scripts"

    <Directory "C:\Program Files\Ampps\www\wsgi-scripts">
    Order allow,deny
    Allow from all
    </Directory>

    WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi"

</VirtualHost>


5. In folder C:\Program Files\Ampps\www created new folder "myapp"
6. In folder C:\Program Files\Ampps\www\myapp put file test.py contents below

Code

#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello World from PythonStandard Hello World from a Python"


7. Open in browser http://localhost/myapp/test.py screenshot below, just the code I put in file

Board Image

No sign of working so I'm trying CGI method.

STRANGE THING HAPPENED.

As you said
Quote
Go to AMPPS Application -> Apache Tab -> Configuration Tab. Find Line


I went there to search for a line, scrolled down and saw there went my code there which I put to C:\Program Files\Ampps\apache\conf\httpd.conf I guess that's some other file. So I pasted the code here hoping it would work, restarted apache, unfortunately the output is the same as in screenshot.

Continuing to try with CGI method.

Quote
Before you run test.py, Go to AMPPS Application -> Apache Tab -> Configuration Tab. Find Line
Code
AddHandler cgi-script .cgi .pl

change it to
Code
AddHandler cgi-script .cgi .pl .py

Save the File. Restart Apache.

Copy test.py and paste it to C:\Program Files\Ampps\www\cgi-bin\test.py and

access http://localhost/cgi-bin/test.py




It worked! Thanks a bunch!

Still wondering why WSGI method didn't work. Besides, what is the differences between the two ?

IP: --   

I can't run python scripts
tidus
Group: Member
Post Group: Super Member
Posts: 1121
Status:
Hi,

To start scripting with mod_wsgi :

Quote
1. In folder C:\Program Files\Ampps\www created new folder "wsgi-scripts"

2. in newly created folder C:\Program Files\Ampps\www\wsgi-scripts created file "myapp.wsgi" contents below

Code

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]


3. Opened the file C:\Program Files\Ampps\apache\conf\httpd.conf
4. In file C:\Program Files\Ampps\apache\conf\httpd.conf line 637 pasted the code

Code

<VirtualHost *:80>
    ServerName localhost
    ServerAlias 127.0.0.1
    ServerAdmin webmaster@example.com

    DocumentRoot "C:\Program Files\Ampps\www\wsgi-scripts"

    <Directory "C:\Program Files\Ampps\www\wsgi-scripts">
    Order allow,deny
    Allow from all
    </Directory>

    WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi"

</VirtualHost>


Till step 4, you are correct.

Quote
5. In folder C:\Program Files\Ampps\www created new folder "myapp"
6. In folder C:\Program Files\Ampps\www\myapp put file test.py contents below

Code

#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello World from PythonStandard Hello World from a Python"


5th & 6th step is not needed.

Quote
7. Open in browser http://localhost/myapp/test.py screenshot below, just the code I put in file


Instead of accessing http://localhost/myapp/test.py just access http://localhost/myapp

Because now your wsgi script is mounted at /myapp.

Quote
Still wondering why WSGI method didn't work. Besides, what is the differences between the two ?


There are actually many ways run python on web. This link can explain properly about it. http://docs.python.org/2/howto/webservers.html

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack
IP: --   

I can't run python scripts
memzxi
Group: Member
Post Group: Newbie
Posts: 8
Status:
I thought CGI will be enough, but I want to work with Django, so still I will need to set up WSGI.

tidus, I looked at your last message, repeated steps 1-4 ant tried to access localhost/myapp and it doesn't work. Have you tested it yourself ? Because I have multiple times with fresh installs of ampps 1.9 and couldn't get it working.

I know there are many methods to run python, but I only need one working WSGI.
IP: --   

I can't run python scripts
tidus
Group: Member
Post Group: Super Member
Posts: 1121
Status:
Hi,

Copy the following contents in Ampps/conf/python.conf and Save.:

Code
LoadModule wsgi_module modules/mod_wsgi.so
DirectoryIndex  index.wsgi default.wsgi index.py default.py
WSGIPythonPath "C:/Program Files/AMPPS/python/Lib;C:/Program Files/AMPPS/python/Lib/site-packages;C:/Program Files/AMPPS/python/DLLs"
WSGIPythonHome "C:/Program Files/AMPPS/python"


Try running the same script again.

Edited by tidus : January 15, 2013, 5:11 am

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack
IP: --   

I can't run python scripts
tidus
Group: Member
Post Group: Super Member
Posts: 1121
Status:
Hi,

To install Django you can follow their doc :
https://docs.djangoproject.com/en/1.4/topics/install/

mod_wsgi module is already loaded in AMPPS which is required by Django.

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack
IP: --   

I can't run python scripts
memzxi
Group: Member
Post Group: Newbie
Posts: 8
Status:
Quote From : tidus January 15, 2013, 5:09 am
Hi,

Copy the following contents in Ampps/conf/python.conf and Save.:

Code
LoadModule wsgi_module modules/mod_wsgi.so
DirectoryIndex  index.wsgi default.wsgi index.py default.py
WSGIPythonPath "C:/Program Files/AMPPS/python/Lib;C:/Program Files/AMPPS/python/Lib/site-packages;C:/Program Files/AMPPS/python/DLLs"
WSGIPythonHome "C:/Program Files/AMPPS/python"


Try running the same script again.


Nope, still doesn't work.

Quote
Not Found

The requested URL /myapp was not found on this server.


I think the problem might be because of placing wsgi-scripts in www. I tried to place instead in C:\Program Files\Ampps\wsgi-scripts but it didn't help either
IP: --   

I can't run python scripts
tidus
Group: Member
Post Group: Super Member
Posts: 1121
Status:
Hi,

And did you try the Django docs ?

-----------------------
Follow AMPPS on,
Twitter : https://twitter.com/AMPPS_Stack
Facebook :  http://www.facebook.com/softaculousampps
Google+ : https://plus.google.com/+AmppsStack
IP: --   

« Previous    Next »

Threaded Mode | Print  

1


Jump To :


Users viewing this topic
1 guests, 0 users.


All times are GMT. The time now is March 28, 2024, 8:30 am.

  Powered By AEF 1.0.8 © 2007-2008 Electron Inc.Queries: 11  |  Page Created In:0.023