Archive

Archive for March, 2012

Install Port on Mac

March 30, 2012 Leave a comment

Eventually, get the Port installed on my Mac. Here’s the step:

Download source of port or the dmp for your mac

For Source(this is from the official Port site, just follow the step):

  1. “cd” into the directory where you downloaded the package and run “tar xjvf MacPorts-2.0.4.tar.bz2” or “tar xzvf MacPorts-2.0.4.tar.gz”, depending on whether you downloaded the bz2 tarball or the gz one, respectively.
  2. Build and install the recently unpacked sources:
    • cd MacPorts-2.0.4
    • ./configure && make && sudo make install

Alternatively, you can also use their “dmg” disk images for Lion and Snow Leopard. It’s very simple, just double click the downloaded dmg, follow the steps 🙂

OK, then here’s my problem. When I open the terminal, my port is not there! Why? You have to update your profile.

  • Change your profile to include MacPort in the PATH, add the following

vi $HOME/.profile

#!/usr/bin/bash

# MacPort

export PATH=$PATH:/opt/local/bin

  • Don’t forget to Source your profile to include the changes, in the terminal, type:

. $HOME/.profile

 

Now, update the port:

sudo port -v selfupdate

and install packages with

sudo port install <package name>

 

By default, you port is install at

So you can do this too without update your profile:

                        sudo /opt/local/bin/port -v selfupdate


Categories: Programming

Configure Apache web server for Python on Windows

March 26, 2012 Leave a comment

Configure the Apache web server to run Python programs on Windows machines.

For detailed information, please check the below link:
http://www.editrocket.com/articles/python_apache_windows.html
http://www.editrocket.com/articles/apache_windows.html

1. Install Python and Apache
Python: http://python.org/download/.
Apache: http://httpd.apache.org/download.cgi

2. Configure Apache to run Python CGI

The next step is to edit ‘httpd.conf’ apache configuration file located in the apache install directory in the conf directory. Search the httpd.conf file for the line

Options Indexes FollowSymLinks

Add ExecCGI to the end of the line. The line should now look similar to the following (NOTE: there may be more options listed):

Options Indexes FollowSymLinks ExecCGI

Next, search for the following:

#AddHandler cgi-script .cgi

Uncomment this line by removing the # in front of the line, and add a .py to the end of the line. The new line should look like this:

AddHandler cgi-script .cgi .py

3. Restart Apache

Now, the apache web server needs to be restarted. You can do this either via the Apache service located in the services control panel or via the Start -> All Programs -> Apache . . . -> Control Apache Server menu option.

4. Run a test Python page

You can use the EditRocket hello world Python sample web page template for a test Python page. This is located in File -> New From Template -> python -> Sample_Web_Page. The following is an example of the template:

#!/usr/bin/python
print “Content-type: text/html”
print
print “<html><head>”
print “”
print “</head><body>”
print “Hello.”
print “</body></html>”

Note the line #!/usr/bin/python. This line needs changed to match the location of your Python installation. For example,

#!/Python27/python

Here is an example assuming Python is installed in the C:\Python27 location

#!/Python26/python
print “Content-type: text/html”
print
print “<html><head>”
print “”
print “</head><body>”
print “Hello.”
print “</body></html>”

Save this file as test.py to your htdocs folder under your apache installation directory. Open your web browser and type in your apache host (and :port if the port is something other than 80) followed by test.py, for example

http://localhost/test.py

Some Useful Links for python-cgi

March 3, 2012 Leave a comment