<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mobile and gis dev notes &#187; python</title>
	<atom:link href="http:///wordpress/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>by rupert</description>
	<lastBuildDate>Wed, 08 Feb 2012 22:26:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>homebrew + python</title>
		<link>/wordpress/2011/12/homebrew-python/</link>
		<comments>/wordpress/2011/12/homebrew-python/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 21:14:06 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=1140</guid>
		<description><![CDATA[Read http://docs.python-guide.org/en/latest/starting/installation/ Installation /usr/local/Cellar% brew install python --framework ==&#62; Downloading http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2 File already downloaded in /Users/rupert/Library/Caches/Homebrew ==&#62; Patching patching file Lib/whichdb.py Hunk #1 succeeded at 91 with fuzz 1. ==&#62; ./configure --prefix=/usr/local/Cellar/python/2.7.2 --enable-framework=/usr/local/Cellar/python/2.7.2/Frameworks ==&#62; make ==&#62; make install ==&#62; Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.24.tar.gz File already downloaded in /Users/rupert/Library/Caches/Homebrew ==&#62; /usr/local/Cellar/python/2.7.2/bin/python setup.py install ==&#62; Caveats A &#34;distutils.cfg&#34; has [...]]]></description>
			<content:encoded><![CDATA[<p>Read <a href="http://docs.python-guide.org/en/latest/starting/installation/">http://docs.python-guide.org/en/latest/starting/installation/</a></p>
<p><strong>Installation</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">/usr/local/Cellar% brew install python --framework
==&gt; Downloading http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
File already downloaded in /Users/rupert/Library/Caches/Homebrew
==&gt; Patching
patching file Lib/whichdb.py
Hunk #1 succeeded at 91 with fuzz 1.
==&gt; ./configure --prefix=/usr/local/Cellar/python/2.7.2 --enable-framework=/usr/local/Cellar/python/2.7.2/Frameworks
==&gt; make
==&gt; make install
==&gt; Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.24.tar.gz
File already downloaded in /Users/rupert/Library/Caches/Homebrew
==&gt; /usr/local/Cellar/python/2.7.2/bin/python setup.py install
==&gt; Caveats
A &quot;distutils.cfg&quot; has been written to:
  /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils
specifing the install-scripts folder as:
  /usr/local/share/python
&nbsp;
If you install Python packages via &quot;python setup.py install&quot;, easy_install, pip,
any provided scripts will go into the install-scripts folder above, so you may
want to add it to your PATH.
&nbsp;
Distribute has been installed, so easy_install is available.
To update distribute itself outside of Homebrew:
    /usr/local/share/python/easy_install pip
    /usr/local/share/python/pip install --upgrade distribute
&nbsp;
See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
&nbsp;
Framework Python was installed to:
  /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework
&nbsp;
You may want to symlink this Framework to a standard OS X location,
such as:
    mkdir ~/Frameworks
    ln -s &quot;/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework&quot; ~/Frameworks
==&gt; Summary
/usr/local/Cellar/python/2.7.2: 4808 files, 77M, built in 86 seconds
brew install python --framework  76.78s user 21.49s system 112% cpu 1:27.00 total</pre></div></div>

<p><strong>Symlinks</strong></p>
<p>The following links were created below to ensure that 2.7 is the latest Python picked up during installation of other software (i.e postgresql)</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">sudo ln -s /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/2.7
sudo ln -s /usr/local/share/python/easy_install /usr/bin/easy_install
sudo ln -s /usr/local/share/python/easy_install-2.7 /usr/bin/easy_install-2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /usr/bin/python2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config /usr/bin/python2.7-config
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc2.7 /usr/bin/pydoc2.7
sudo ln -s /usr/bin/python2.7 /usr/bin/python
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/Current
mkdir -p /Library/Python/2.7
ln -s /usr/local/lib/python2.7/site-packages /Library/Python/2.7/site-packages</pre></div></div>

<p><strong>Site-Packages. Where?</strong></p>
<p>Note that <strong>site-packages</strong> will be installed in</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">/usr/local/lib/python2.7/site-packages</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% ls -la /Library/Python/2.6/site-packages
total 136
drwxrwxr-x  14 root    admin    476 30 Dec 18:13 ./
drwxrwxr-x   4 root    admin    136 30 Dec 18:11 ../
-rw-r--r--@  1 rupert  admin   6148 30 Dec 18:13 .DS_Store
-rw-rw-r--   1 root    admin    119 11 Feb  2010 README
-rw-r--r--   1 rupert  admin    241 30 Dec 18:01 easy-install.pth
-rw-r--r--   1 rupert  admin   3129 30 Dec 18:02 googlemaps-1.0.2-py2.6.egg-info
-rw-r--r--   1 rupert  admin  19703 16 Oct  2009 googlemaps.py
-rw-r--r--   1 rupert  admin  19153 30 Dec 18:02 googlemaps.pyc
drwxr-xr-x  39 root    admin   1326  7 Feb  2010 mod_python/
-rw-r--r--   1 root    admin    267  7 Feb  2010 mod_python-3.3.2_dev_20080819-py2.6.egg-info
drwxr-xr-x   8 rupert  admin    272 30 Dec 18:13 nominatim/
-rw-r--r--   1 rupert  admin   4462 30 Dec 18:08 nominatim-0.90-py2.6.egg
drwxr-xr-x  15 rupert  admin    510 30 Dec 18:01 simplejson/
drwxr-xr-x   4 rupert  admin    136 30 Dec 18:13 simplejson-2.3.1-py2.6.egg/
~% ls -la /Library/Python/2.7/site-packages
lrwxr-xr-x  1 root  admin  38 30 Dec 18:23 /Library/Python/2.7/site-packages@ -&gt; /usr/local/lib/python2.7/site-packages</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% which python
/usr/local/bin/python
~% python --version
Python 2.7.2</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/12/homebrew-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jpeg decoder problem on TileCache on MacOSX Leopard</title>
		<link>/wordpress/2008/05/jpeg-decoder-problem-on-tilecache-on-macosx-leopard/</link>
		<comments>/wordpress/2008/05/jpeg-decoder-problem-on-tilecache-on-macosx-leopard/#comments</comments>
		<pubDate>Mon, 12 May 2008 07:26:07 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[tilecache]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=184</guid>
		<description><![CDATA[There is a problem with a &#8220;jpeg decoder&#8221; because Python Imaging Library (PIL) cannot find the jpeg libraries. Remember that we installed kyngchaos UnixIO libraries, therefore the PIL setup.py script should point to use those libraries. Actually, I even installed the jpegsrc manually. I believe there is no need to do this, since UnixIO Image [...]]]></description>
			<content:encoded><![CDATA[<p>There is a problem with a <em>&#8220;jpeg decoder&#8221;</em> because <a href="http://www.pythonware.com/products/pil/">Python Imaging Library (PIL)</a> cannot find the jpeg libraries. Remember that we installed <a href="http://www.kyngchaos.com/wiki/software:frameworks">kyngchaos UnixIO libraries</a>, therefore the PIL setup.py script should point to use those libraries. </p>
<p>Actually, I even installed the jpegsrc manually. I believe there is no need to do this, since UnixIO Image libraries is sufficient enough for PIL to install. What is important is to ensure that python tests succeeded. Once you get passed that, then installing PIL should work.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">1. Extract Imaging-1.1.6.tar.gz
2. Edit setup.py to reflect:
<span style="color: #007800;">JPEG_ROOT</span>=<span style="color: #ff0000;">&quot;/Library/Frameworks/UnixImageIO.framework/unix&quot;</span>
3. python setup.py build_ext <span style="color: #660033;">-i</span>
4. If no <span style="color: #7a0874; font-weight: bold;">test</span> fails, <span style="color: #000000; font-weight: bold;">then</span> go ahead and <span style="color: #c20cb9; font-weight: bold;">install</span>
5. python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/05/jpeg-decoder-problem-on-tilecache-on-macosx-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing Point Outliers</title>
		<link>/wordpress/2007/11/removing-point-outliers/</link>
		<comments>/wordpress/2007/11/removing-point-outliers/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 14:31:07 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=125</guid>
		<description><![CDATA[In my previous post to remove point outliers, I tried using R and PLR in PostGres. Although, I only scratched the surface on the spatial analyzing capabilities of R, I needed something more extensible for my internet purposes. I decided to use Python&#8217;s pragmatic benefits and ease in programming. Idea was to pull out the [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post to remove point outliers, I tried using <a href="/wordpress/?p=121">R and PLR in PostGres</a>. Although, I only <a href="http://www.bostongis.com/?content_name=postgresql_plr_tut01#87">scratched the surface on the spatial analyzing capabilities of R</a>, I needed something more extensible for my internet purposes.  I decided to use Python&#8217;s pragmatic benefits and ease in programming.  Idea was to pull out the vector points from PostGIS, process it using an algorithm (ideally minimum convex hull but it could be expensive later on) and then remove the outliers.</p>
<p><a href="http://www.scipy.org/Cookbook">Numpy</a>, a scientific python library, blends easily by using basic functions for mathematical array computations such as mean, median, standard deviation and variance.  For now, the algorithm takes a 90% threshold, taken from <a href="http://www.uoregon.edu/~robinh/outl.txt">&#8220;Dealing with &#8216;Outliers&#8217;: Maintain Your Data&#8217;s Integrity&#8221;</a></p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Consider this collection of 10 scores, sorted from smallest to largest:
&nbsp;
  x    8 25 35 41 50   75 75 79 92 129
                     ^
The median of these 10 values of x is 62.5, computed as (75+50)/2.
&nbsp;
Next, calculate the absolute value of the deviation of original data from median:
&nbsp;
   x     med  abs_dev
&nbsp;
  50    62.5    12.5
  75    62.5    12.5
  75    62.5    12.5
  79    62.5    16.5
  41    62.5    21.5 -&amp;gt;|
  35    62.5    27.5 -&amp;gt;|  MEDIAN(abs_dev) = 24.5 = (21.5+27.5)/2
  92    62.5    29.5
  25    62.5    37.5
   8    62.5    54.5
 129    62.5    66.5
&nbsp;
Next, compute a test statistic which is the column of absolute values computed above, divided by the mediate of the absolute values:
&nbsp;
Test Stat = abs_dev / (Med of abs Dev)
&nbsp;
                           Med of       Test
  x    Median  abs_dev    abs dev    Statistic  Outlier?   
&nbsp;
  8     62.5     54.5       24.5      2.22449
 25     62.5     37.5       24.5      1.53061
 35     62.5     27.5       24.5      1.12245
 41     62.5     21.5       24.5      0.87755
 50     62.5     12.5       24.5      0.51020
 75     62.5     12.5       24.5      0.51020
 75     62.5     12.5       24.5      0.51020
 79     62.5     16.5       24.5      0.67347
 92     62.5     29.5       24.5      1.20408
129     62.5     66.5       24.5      2.71429       Yes
&nbsp;
The decision rule then is to compare this test statistic with an arbitrary cutoff point. A cutoff of 2.5 is conservative; 4.5 or 5 is more rigorous. If the Test Statistic &amp;gt; Critical value (=2.5), then define the observed value as an outlier. According to this cutoff value, the data above have one outlier (x=129).</pre></div></div>

</blockquote>
<p>Implementing this in Python&#8230;</p>
<p>P = 116.32977 39.905319,116.329906 39.90464,116.329907 39.90464,116.329918 39.904675,116.330047 39.904683</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    multipoints = getPointsString<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> multipoints
&nbsp;
    pobj = getPointArray<span style="color: black;">&#40;</span>multipoints<span style="color: black;">&#41;</span>
    p = pobj.<span style="color: black;">p</span><span style="color: #66cc66;">;</span>
    x = pobj.<span style="color: black;">x</span><span style="color: #66cc66;">;</span>
    y = pobj.<span style="color: black;">y</span><span style="color: #66cc66;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#print &quot;Median:&quot;,  median(p)</span>
    <span style="color: #808080; font-style: italic;">#print &quot;Std:&quot;,  p.std(axis=0)</span>
    <span style="color: #808080; font-style: italic;">#print &quot;Min:&quot;, p.min(axis=0)</span>
    <span style="color: #808080; font-style: italic;">#print &quot;Max:&quot;, p.max(axis=0)</span>
&nbsp;
    pmed = median<span style="color: black;">&#40;</span>p<span style="color: black;">&#41;</span>
    pdev = p - pmed
    pdev_abs = <span style="color: #008000;">abs</span><span style="color: black;">&#40;</span>pdev<span style="color: black;">&#41;</span>
    med_pdev = median<span style="color: black;">&#40;</span> pdev_abs <span style="color: black;">&#41;</span>
    pfinal = pdev_abs / med_pdev</pre></div></div>

<p>Where getPointsString() = &#8220;116.32977 39.905319,116.329906 39.90464,116.329907 39.90464,116.329918 39.904675,116.330047 39.904683..&#8221; a list of point geometries. We can easily get the median, std, and even minimum (min) and maximum (max) values in the array.</p>
<p><a href="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/11/2007-11-19_102428.png" title="2007-11-19_102428.png"><img src="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/11/2007-11-19_102428.png" alt="2007-11-19_102428.png" /></a></p>
<p>Here the original dots are marked as red, while the final dots after removing the outliers were colored as green.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/11/removing-point-outliers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyDev Plugin For Eclipse</title>
		<link>/wordpress/2007/11/pydev-plugin-for-eclipse/</link>
		<comments>/wordpress/2007/11/pydev-plugin-for-eclipse/#comments</comments>
		<pubDate>Sat, 03 Nov 2007 00:30:40 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">/wordpress/?p=112</guid>
		<description><![CDATA[I had &#8220;indentation&#8221; problems a few times when I was doing Python using vim. Also, my chinese characters were not displaying correctly on VIM as well. But when I open the file in IDLE, I can read the chinese characters fine. Well I found a quick workaround for my indent problem by using the default [...]]]></description>
			<content:encoded><![CDATA[<p>I had <em>&#8220;indentation&#8221;</em> problems a few times when I was doing Python using vim. Also, my chinese characters were not displaying correctly on VIM as well.  But when I open the file in IDLE, I can read the chinese characters fine.  Well I found a quick workaround for my indent problem by using the default Python Editor which is IDLE:</p>
<p>1. Edit -&gt; Select ALL<br />
2. Format -&gt; Untabify Region<br />
3. Specify &#8220;4&#8243; spaces for the tabs.<br />
4. To run your program, just press F5.</p>
<p>Well, just recently I managed some time and went to the ShowMeDo site for Python. There I found out about PyDev, please watch the <a href="pydevhttp://showmedo.com/videos/series?name=PyDevEclipseList">screencast</a>, its worth it! Firing Eclipse, I immediately added the plugin from the update site: <a href="http://pydev.sourceforge.net/updates/">http://pydev.sourceforge.net/updates/</a>.</p>
<p><a href="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/11/python.png" title="PyDev Plugin For Eclipse"><img src="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/11/python.thumbnail.png" alt="PyDev Plugin For Eclipse" /></a></p>
<p>Once you have PyDev set, you need to tell Eclipse where your PYTHON bin, PYTHONPATH and other settings.<br />
1. Go to Window -&gt; Preferences<br />
2. Collapse PyDev from left panel<br />
3. Select &#8220;Interpreter-Python&#8221;<br />
4. Click on <strong><em>&#8220;New&#8221;</em></strong> on the <strong>&#8220;Python Interpreters&#8221;</strong> Group.<br />
5. Specify where python.exe.</p>
<p>Note: It would automatically add the libraries in your PYTHONPATH. Again, I insist you watch the <a href="pydevhttp://showmedo.com/videos/series?name=PyDevEclipseList">screencast</a> from Fabio to guide you through. To run your program just hit &#8220;F9&#8243;.</p>
<p><a href="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/11/pydev_config.png" title="Python Config"><img src="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/11/pydev_config.thumbnail.png" alt="Python Config" /></a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/11/pydev-plugin-for-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Variable scoping in Python</title>
		<link>/wordpress/2007/10/variable-scoping-in-python/</link>
		<comments>/wordpress/2007/10/variable-scoping-in-python/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 11:47:11 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=109</guid>
		<description><![CDATA[In python, variables defined in a function is only local to that function. def myfunct&#40;&#41;: i = 1 return &#34;Hello World&#34; &#160; i = 0 print myfunct&#40;&#41; print i When you run the code above, it would spit out: &#62;&#62;&#62; Hello 0 &#62;&#62;&#62; In order to manipulate a variable within the function defined in main, [...]]]></description>
			<content:encoded><![CDATA[<p>In python, variables defined in a function is only local to that function.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> myfunct<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    i = <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;Hello World&quot;</span>
&nbsp;
i = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">print</span> myfunct<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> i</pre></div></div>

<p>When you run the code above, it would spit out:<br />
<code><br />
&gt;&gt;&gt;<br />
Hello<br />
0<br />
&gt;&gt;&gt;<br />
</code></p>
<p>In order to manipulate a variable within the function defined in main, we need to use &#8216;<em>global</em>&#8216;.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> myfunct<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">global</span> i
    i = <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;Hello World&quot;</span>
&nbsp;
i = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">print</span> myfunct<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> i</pre></div></div>

<p>When you run the code above, it would spit out:<br />
<code><br />
&gt;&gt;&gt;<br />
Hello<br />
1<br />
&gt;&gt;&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/10/variable-scoping-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diving into Python</title>
		<link>/wordpress/2007/08/diving-into-python/</link>
		<comments>/wordpress/2007/08/diving-into-python/#comments</comments>
		<pubDate>Sat, 11 Aug 2007 16:09:01 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=97</guid>
		<description><![CDATA[Yup, Im now diving into Python. So far, Im loving it. Not as hard as java, very pragmatic programming. I got converted when I saw Awaretek&#8217;s &#8220;Python Learning Foundation&#8221; which I believe deserves a lot of merit for promoting Python. One of the podcasts from www.directionmag.com states that Python is #4 among GIS professional as [...]]]></description>
			<content:encoded><![CDATA[<p>Yup, Im now diving into Python. So far, Im loving it. Not as hard as java, very pragmatic programming.  I got converted when I saw <a href="http://www.awaretek.com/tutorials.html">Awaretek&#8217;s &#8220;Python Learning Foundation&#8221;</a> which I believe deserves a lot of merit for promoting Python.  One of the podcasts from <a href="www.directionsmag.com">www.directionmag.com</a> states that Python is #4 among GIS professional as a <em>must-have</em> progamming language experience.</p>
<p>Moving forward, I kickstarted with a few tutorials. Fast-reading most of the tutorials from <a href="http://www.upriss.org.uk/python/PythonCourse.html">http://www.upriss.org.uk/python/PythonCourse.html</a> and trying out the exercises. It was fabolous. Simple yet powerful. Then I saw Alex Martelli&#8217;s tutorial from <a href="http://www.aleax.it/Python/py25.pdf">http://www.aleax.it/Python/py25.pdf</a>. Those who have programming experience like Java/C, would benefit much from Martell&#8217;s PDF tutorial.</p>
<p>Next stop.. using databases with python.. Head on to the database section of <a href="http://www.awaretek.com/tutorials.html">AwareTek</a>.</p>
<p>1. I&#8217;ve dowloaded Python&#8217;s DB Interface for Postgres &#8216;<em>psycopg2</em>&#8216;.  <a href="http://www.initd.org/tracker/psycopg/wiki/PsycopgTwo">http://www.initd.org/tracker/psycopg/wiki/PsycopgTwo</a></p>
<p>2. <a href="http://holdenweb.blogspot.com/2007/02/tutorial-is-ready.html">Steve Holden&#8217;s dbPythonIntro.pdf</a>. Presents a quick overview of the DB API. Important pages would be:</p>
<ul>
<li>26/65 Connection Example (includes Postgres)</li>
<li>29/65 Connection Methods</li>
<li>30/65 Executing Queries</li>
<li>31/65 Retrieving Results</li>
</ul>
<p>3. <a href="http://www.devx.com/opensource/Article/29071">Accessing PostgreSQL with Python and Psycopg2</a>. This three page tutorial will quickly give you a background of how to execute queries, fetch queries using <em>column index</em> or by <em>names</em>.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/08/diving-into-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing TileCache on RedHat/CentOS</title>
		<link>/wordpress/2007/07/installing-tilecache/</link>
		<comments>/wordpress/2007/07/installing-tilecache/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 10:36:45 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mapserver]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tilecache]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[centos]]></category>

		<guid isPermaLink="false">/wordpress/?p=79</guid>
		<description><![CDATA[1. Install Apache ./configure &#8211;prefix=/usr/local/apache2 &#8211;enable-so &#8211;enable-rewrite &#8211;with-mpm=prefork make make install rm -Rf /usr/local/apache2/htdocs/* 2. Install mod_python-3.3.1 ./configure --with-apxs=/usr/local/apache2/bin/apxs make make install 3. Install Python Imaging Library (PIL) &#8211; Imaging-1.1.6 python setup.py install Note: To check if PIL was successfully installed: #python selftest.py ***Test Failed*** 1 failures. *** 1 tests of 57 failed. 47 ln [...]]]></description>
			<content:encoded><![CDATA[<p>1. Install Apache<br />
./configure &#8211;prefix=/usr/local/apache2 &#8211;enable-so &#8211;enable-rewrite &#8211;with-mpm=prefork<br />
make<br />
make install<br />
rm -Rf /usr/local/apache2/htdocs/*</p>
<p>2. Install mod_python-3.3.1<br />
<code><br />
./configure --with-apxs=/usr/local/apache2/bin/apxs<br />
make<br />
make install<br />
</code></p>
<p>3. Install Python Imaging Library (PIL) &#8211; Imaging-1.1.6<br />
<code><br />
python setup.py install<br />
</code></p>
<p>Note: To check if PIL was successfully installed:<br />
#python selftest.py<br />
***Test Failed*** 1 failures.<br />
*** 1 tests of 57 failed.</p>
<p>   47  ln -s /usr/lib/libjpeg.so.62 /usr/lib/libjpeg.so<br />
   48  ldconfig<br />
   49  python setup.py install<br />
   51  python selftest.py<br />
   54  rm -rf Imaging-1.1.6<br />
   55  tar -zxvf Imaging-1.1.6.tar.gz<br />
   56  cd Imaging-1.1.6<br />
   58  python selftest.py -> still fails<br />
   59  python setup.py install<br />
   60  python selftest.py -> ok</p>
<p>4. Check if mod_python was sucessfully installed.<br />
<a href="http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking">http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking</a></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#91;</span>root@rupert-centos pytest<span style="color: black;">&#93;</span><span style="color: #808080; font-style: italic;"># python</span>
Python 2.4.3 <span style="color: black;">&#40;</span><span style="color: #808080; font-style: italic;">#1, Mar 14 2007, 18:51:08)</span>
<span style="color: black;">&#91;</span>GCC 4.1.1 <span style="color: #ff4500;">20070105</span> <span style="color: black;">&#40;</span>Red Hat 4.1.1-<span style="color: #ff4500;">52</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> on linux2
Type <span style="color: #483d8b;">&quot;help&quot;</span>, <span style="color: #483d8b;">&quot;copyright&quot;</span>, <span style="color: #483d8b;">&quot;credits&quot;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;license&quot;</span> <span style="color: #ff7700;font-weight:bold;">for</span> more information.
<span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff7700;font-weight:bold;">import</span> mod_python
<span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span> mod_python.<span style="color: black;">version</span>
<span style="color: #483d8b;">'3.3.1'</span>
<span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span></pre></div></div>

<p>4. Edit httpd.conf</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">&lt;directory&gt;
 AddHandler python-program .py
 PythonHandler TileCache.Service
 PythonOption TileCacheConfig /usr/local/apache2/htdocs/tilecache/tilecache.cfg
 PythonDebug On
 PythonPath &quot;sys.path + ['/usr/local/apache2/htdocs/tilecache/']&quot;
&lt;/directory&gt;
&nbsp;
&lt;directory&gt;
 AddHandler mod_python .py
 PythonHandler test
 PythonDebug On
&lt;/directory&gt;</pre></div></div>

<blockquote><p>Note: This syntax will work for all versions of mod_python. In version 3.0 and later, the name of the mod_python handler reference has actually been changed and thus it is now preferred to use &#8220;mod_python&#8221; instead of &#8220;python-program&#8221;. The old name though is still supported and will be used here to avoid confusion for those using version 2.7.</p></blockquote>
<p>5. Test your python</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> mod_python <span style="color: #ff7700;font-weight:bold;">import</span> apache
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> handler<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>:
      req.<span style="color: black;">log_error</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'handler'</span><span style="color: black;">&#41;</span>
      req.<span style="color: black;">content_type</span> = <span style="color: #483d8b;">'text/plain'</span>
      req.<span style="color: black;">send_http_header</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      req.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'mptest.py<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">return</span> apache.<span style="color: black;">OK</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/07/installing-tilecache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transparent Overlays in TileCache</title>
		<link>/wordpress/2007/03/transparent-overlays-in-tilecache/</link>
		<comments>/wordpress/2007/03/transparent-overlays-in-tilecache/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 17:21:53 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mapserver]]></category>
		<category><![CDATA[tilecache]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[openlayers]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=44</guid>
		<description><![CDATA[From the tilecache mailing list&#8230;. Hi Everyone, Really appreciate all the replies&#8230; 1. Installed Imaging-1.1.6.tar.gz (PIL). &#91;root@rupert-linux ~&#93;# python Python 2.3.4 &#40;#1, Mar 10 2006, 06:12:09) [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 Type &#34;help&#34;, &#34;copyright&#34;, &#34;credits&#34; or &#34;license&#34; for more information. &#38;gt;&#38;gt;&#38;gt; import sys &#38;gt;&#38;gt;&#38;gt; print sys.path &#91;'', '/usr/lib/python23.zip', '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload', [...]]]></description>
			<content:encoded><![CDATA[<p>From the tilecache mailing list&#8230;.</p>
<p>Hi Everyone,</p>
<p>Really appreciate all the replies&#8230;</p>
<p>1. Installed Imaging-1.1.6.tar.gz (PIL).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>rupert-linux ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># python</span>
Python 2.3.4 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #666666; font-style: italic;">#1, Mar 10 2006, 06:12:09) [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.</span>
<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; import sys
<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; print sys.path
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">''</span>, <span style="color: #ff0000;">'/usr/lib/python23.zip'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/plat-linux2'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/lib-tk'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/lib-dynload'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/site-packages'</span>,
<span style="color: #ff0000;">'/usr/lib/python2.3/site-packages/PIL'</span>,
<span style="color: #ff0000;">'/usr/lib/python2.3/site-packages/gtk-2.0'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;</pre></div></div>

<p>2. Modified test1.cfm</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">     41         var options = {
     42                         controls: [new OpenLayers.Control.MouseDefaults()]
     43                       };
     44
     45         map = new OpenLayers.Map( $('map'), options);
     46
     47         var layer_base = new OpenLayers.Layer.WMS(
     48                     &quot;Base Layer&quot;,
     49                     &quot;<span style="color: #0000FF;">#request.mapserv_tile#</span>&quot;,
     50                     {
     51                         map: '/home/map/beijing/new/wms.map',
     52                         layers: '<span style="color: #0000FF;">#request.basemap_tile#</span>',
     53                         format: 'image/png', 'transparent': 'false'
     54                     }
     55                     );
     56
     57         var layer_road = new OpenLayers.Layer.WMS(
     58                     &quot;Road Layer&quot;,
     59                     &quot;<span style="color: #0000FF;">#request.mapserv_tile#</span>&quot;,
     60                     {
     61                         map: '/home/map/beijing/new/wms.map',
     62                         layers: '<span style="color: #0000FF;">#request.roads_tile#</span>',
     63                         format: 'image/png', 'transparent': 'true'
     64                     },
     65                     {
     66                         reproject: false
     67                     }
     68                     );
     69
     70         map.addLayer(layer_base);
     71         layer_base.setIsBaseLayer(true);
     72
     73         layer_road.setIsBaseLayer(false);
     74         map.addLayer(layer_road);</pre></div></div>

<p>3. tilecache.cfg. Commented metaTile=true http://222.128.19.19/tilecache/tilecache.cfg</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">     <span style="color: #000000;">47</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>basemap<span style="color: #7a0874; font-weight: bold;">&#93;</span>
     <span style="color: #000000;">48</span> <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">type</span></span>=WMSLayer
     <span style="color: #000000;">49</span> <span style="color: #007800;">url</span>=http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1<span style="color: #000000; font-weight: bold;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;">/</span>mapserv?<span style="color: #007800;">map</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>map<span style="color: #000000; font-weight: bold;">/</span>beijing<span style="color: #000000; font-weight: bold;">/</span>new<span style="color: #000000; font-weight: bold;">/</span>wms.map
     <span style="color: #000000;">50</span> <span style="color: #007800;">layers</span>=district,greens,major_river,minor_river
     <span style="color: #000000;">51</span> <span style="color: #666666; font-style: italic;">#bbox=-180,-90,180,90</span>
     <span style="color: #000000;">52</span> <span style="color: #666666; font-style: italic;">#metaTile=true</span>
     <span style="color: #000000;">53</span> <span style="color: #007800;">extension</span>=png
     <span style="color: #000000;">54</span>
     <span style="color: #000000;">55</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>roads<span style="color: #7a0874; font-weight: bold;">&#93;</span>
     <span style="color: #000000;">56</span> <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">type</span></span>=WMSLayer
     <span style="color: #000000;">57</span> <span style="color: #007800;">url</span>=http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1<span style="color: #000000; font-weight: bold;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;">/</span>mapserv?<span style="color: #007800;">map</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>map<span style="color: #000000; font-weight: bold;">/</span>beijing<span style="color: #000000; font-weight: bold;">/</span>new<span style="color: #000000; font-weight: bold;">/</span>wms.map
     <span style="color: #000000;">58</span> <span style="color: #666666; font-style: italic;">#layers=road4,road4label,road3,road3label,road2,road2label,road1,road1label,road11,road11label</span>
     <span style="color: #000000;">59</span> <span style="color: #666666; font-style: italic;">#bbox=116.1737,39.8211,116.5640,40.0799</span>
     <span style="color: #000000;">60</span> <span style="color: #666666; font-style: italic;">#maxresolution=1.40625</span>
     <span style="color: #000000;">61</span> <span style="color: #666666; font-style: italic;">#bbox=-180,-90,180,90</span>
     <span style="color: #000000;">62</span> <span style="color: #007800;">layers</span>=road1,road1label,road11,road11label
     <span style="color: #000000;">63</span> <span style="color: #007800;">extension</span>=png
     <span style="color: #000000;">64</span> <span style="color: #666666; font-style: italic;">#metaTile=true</span></pre></div></div>

<p>4. Modified wms.map http://222.128.19.19/tilecache/wms.map</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">OUTPUTFORMAT
     NAME png
     DRIVER <span style="color: #ff0000;">&quot;GD/PNG&quot;</span>
     MIMETYPE <span style="color: #ff0000;">&quot;image/png&quot;</span>
     IMAGEMODE RGB
     EXTENSION <span style="color: #ff0000;">&quot;png&quot;</span>
     FORMATOPTION <span style="color: #ff0000;">&quot;INTERLACE=OFF&quot;</span>
END</pre></div></div>

<p>5. Checked access_log. &#8220;transparent=true&#8221; exists&#8230;<br />
<code><br />
192.168.1.150 - - [30/Mar/2007:13:46:26 +0800] "GET /tilecache/tilecache.py?MAP=%2Fhome%2Fmap%2Fbeijing%2Fnew%2Fwms.map&amp;LAYERS=r<br />
oads&amp;FORMAT=image%2Fpng&amp;TRANSPARENT=true&amp;SERVICE=WMS&amp;VERSION=1.1.1&amp;REQUEST=G<br />
etMap&amp;STYLES=&amp;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&amp;SRS=EPSG%3A4326&amp;BB<br />
OX=116.334229%2C39.891357%<br />
2C116.345215%2C39.902344&amp;WIDTH=256&amp;HEIGHT=256 HTTP/1.1" 200 14580<br />
</code></p>
<p>Now, this is really weird. I have &#8220;transparent&#8221;: true in test1.cfm all the time. That didn&#8217;t worked.</p>
<p>For every test iteration i made, I always tried clearing the cache, removing the python compiled scripts, then restarting Apache just to get a clean state..</p>
<p><code><br />
rm -Rf /usr/local/apache2/htdocs/tmp/*<br />
rm /wwwroot/tilecache/TileCache/*.pyc<br />
/etc/init.d/httpd restart<br />
</code></p>
<p>Then I tried appending &#8220;transparent=true&#8221; to tilecache.cfg based on Eric&#8217;s suggestion&#8230;<br />
That worked. Now I wonder why&#8230; Nevertheless, its working now. Again many thanks to everyone&#8230;</p>
<p>Rupert</p>
<p>On Fri, Mar 30, 2007 at 01:57:43PM +0800, Rupert de Guzman Jr wrote:<br />
&gt; Hi Everyone,<br />
&gt;<br />
&gt; Really appreciate all the replies&#8230;<br />
&gt; Then I tried appending &#8220;transparent=true&#8221; to tilecache.cfg based on<br />
&gt; Eric&#8217;s suggestion&#8230;<br />
&gt; That worked. Now I wonder why&#8230; Nevertheless, its working now. Again<br />
&gt; many thanks to everyone&#8230;</p>
<p>TileCache pays almost no attention to the URL: Only the BBOX and the layername matter. Anything else is simply ignored: so your transparency being set in OpenLayers actually has 0 affect.</p>
<p>The reason for this is that TileCache can only store one copy of an image. If the URL parameters modified the content, you could get an inconsistent cache.</p>
<p>This is &#8216;by design&#8217;, insofar as there is no obvious solution (other than to complain more loudly when TC Gets parameters it isn&#8217;t expecting, which is an outstanding FIXME in the code). The lack of error message is not by design, and I&#8217;m sorry you got bit by the poorly documented behavior.</p>
<p>Regards,<br />
&#8211;<br />
Christopher Schmidt<br />
MetaCarta</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/03/transparent-overlays-in-tilecache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting python_path on Unix</title>
		<link>/wordpress/2007/03/setting-python_path-on-unix/</link>
		<comments>/wordpress/2007/03/setting-python_path-on-unix/#comments</comments>
		<pubDate>Thu, 29 Mar 2007 13:17:54 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mapserver]]></category>
		<category><![CDATA[tilecache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=43</guid>
		<description><![CDATA[At the time of this writing.. download mod_python-3.3.1.tgz ./configure &#8211;with-apxs=/usr/local/apache2/bin/apxs make make install You need to pass the PYTHONPATH to apache.. AddHandler python-program .py PythonHandler TileCache.Service PythonOption TileCacheConfig /usr/local/apache2/htdocs/tilecache/tilecache.cfg PythonDebug On PythonPath &#8220;sys.path + ['/usr/local/apache2/htdocs/tilecache/']&#8221; In your bash shells, you could also check the PYTHONPATH&#8230; &#91;root@rupert-linux views&#93;# python Python 2.3.4 &#40;#1, Mar 10 2006, 06:12:09) [...]]]></description>
			<content:encoded><![CDATA[<p>At the time of this writing.. download mod_python-3.3.1.tgz</p>
<p>./configure &#8211;with-apxs=/usr/local/apache2/bin/apxs<br />
make<br />
make install</p>
<p>You need to pass the PYTHONPATH to apache..<br />
<directory><br />
AddHandler python-program .py<br />
PythonHandler TileCache.Service<br />
PythonOption TileCacheConfig /usr/local/apache2/htdocs/tilecache/tilecache.cfg<br />
PythonDebug On<br />
PythonPath &#8220;sys.path + ['/usr/local/apache2/htdocs/tilecache/']&#8221;<br />
</directory></p>
<p>In your bash shells, you could also check the PYTHONPATH&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>rupert-linux views<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># python</span>
Python 2.3.4 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #666666; font-style: italic;">#1, Mar 10 2006, 06:12:09)</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>GCC 3.4.5 <span style="color: #000000;">20051201</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Red Hat 3.4.5-<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> on linux2
Type <span style="color: #ff0000;">&quot;help&quot;</span>, <span style="color: #ff0000;">&quot;copyright&quot;</span>, <span style="color: #ff0000;">&quot;credits&quot;</span> or <span style="color: #ff0000;">&quot;license&quot;</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">more</span> information.
<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; import sys
<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; print sys.path
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">''</span>, <span style="color: #ff0000;">'/usr/lib/python23.zip'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/plat-linux2'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/lib-tk'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/lib-dynload'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/site-packages'</span>, <span style="color: #ff0000;">'/usr/lib/python2.3/site-packages/gtk-2.0'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/03/setting-python_path-on-unix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing MS4W, Python2.4, ColdFusion6.1</title>
		<link>/wordpress/2007/01/installing-ms4w-python24-coldfusion61/</link>
		<comments>/wordpress/2007/01/installing-ms4w-python24-coldfusion61/#comments</comments>
		<pubDate>Tue, 16 Jan 2007 23:55:12 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mapserver]]></category>
		<category><![CDATA[ms4w]]></category>
		<category><![CDATA[cf]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=21</guid>
		<description><![CDATA[For Windows: A. Installing MS4W 1. Download ms4w2.2 from maptools.org 2. Extract ms4w2.2 into your root drive (E:\) 3. Run E:\ms4w\apache-install.bat. This would install apache2.2 as a service. 4. Edit E:\ms4w\Apache\conf\httpd.conf to reflect your webroot in &#8220;DocumentRoot&#8221; (E:\wwwroot\) 149 DocumentRoot &#34;/wwwroot&#34; ... .... 177 &#60;directory&#62; # # Possible values for the Options directive are &#34;None&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>For Windows:</p>
<p><strong>A.  Installing MS4W</strong><br />
1. Download ms4w2.2 from <a href="http://www.maptools.org/ms4w/index.phtml?page=downloads.html">maptools.org</a></p>
<p>2. Extract ms4w2.2 into your root drive (E:\)</p>
<p>3. Run E:\ms4w\apache-install.bat. This would install apache2.2 as a service.</p>
<p>4. Edit E:\ms4w\Apache\conf\httpd.conf to reflect your webroot in &#8220;DocumentRoot&#8221; (E:\wwwroot\)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">149</span> DocumentRoot <span style="color: #ff0000;">&quot;/wwwroot&quot;</span>
...
....
<span style="color: #000000;">177</span> <span style="color: #000000; font-weight: bold;">&lt;</span>directory<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># Possible values for the Options directive are &quot;None&quot;, &quot;All&quot;,</span>
    <span style="color: #666666; font-style: italic;"># or any combination of:</span>
    <span style="color: #666666; font-style: italic;">#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># Note that &quot;MultiViews&quot; must be named *explicitly* --- &quot;Options All&quot;</span>
    <span style="color: #666666; font-style: italic;"># doesn't give it to you.</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># The Options directive is both complicated and important.  Please see</span>
    <span style="color: #666666; font-style: italic;"># http://httpd.apache.org/docs/2.2/mod/core.html#options</span>
    <span style="color: #666666; font-style: italic;"># for more information.</span>
    <span style="color: #666666; font-style: italic;">#</span>
    Options Indexes FollowSymLinks
&nbsp;
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># AllowOverride controls what directives may be placed in .htaccess files.</span>
    <span style="color: #666666; font-style: italic;"># It can be &quot;All&quot;, &quot;None&quot;, or any combination of the keywords:</span>
    <span style="color: #666666; font-style: italic;">#   Options FileInfo AuthConfig Limit</span>
    <span style="color: #666666; font-style: italic;">#</span>
    AllowOverride None
&nbsp;
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># Controls who can get stuff from this server.</span>
    <span style="color: #666666; font-style: italic;">#</span>
    Order allow,deny
    Allow from all
<span style="color: #000000;">205</span> <span style="color: #000000; font-weight: bold;">&lt;/</span>directory<span style="color: #000000; font-weight: bold;">&gt;</span>
....
....
<span style="color: #000000;">212</span> DirectoryIndex index.html index.html.var index.php index.phtml index.php3 index.cfm
....
....</pre></div></div>

<p>5. Test apache, navigate to &#8220;http://127.0.0.1/&#8221;.</p>
<p><strong>B. Configuring Apache2.2 with ColdFusion6.1</strong><br />
6. Since Apache2.2 was released after CF6.1 and CF7.0 then, it would only bind with Apache2.0.x. We need a new wsconfig.jar that would bind with Apache2.2.x. Read more about the technote:<br />
<a href="http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=8001e97">http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=8001e97</a></p>
<p>Alternatively, you could download wsconfig.jar from <a href="http://www.adobe.com/support/coldfusion/ts/documents/8001e97/wsconfig.zip">http://www.adobe.com/support/coldfusion/ts/documents/8001e97/wsconfig.zip</a></p>
<p>7. Backup your existing wsconfig.jar to wsconfig.jar.bak. Replace the wsconfig.jar.</p>
<p>8. Restart ColdFusion.</p>
<p>9. Remove existing connectors from D:\CFusionMX\bin\connectors\Remove_ALL_connectors.bat</p>
<p>10. Execute D:\CFusionMX\bin\connectors\Apache_connector.bat</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;"><span style="color: #66cc66;">@</span>echo <span style="color: #0080FF; font-weight: bold;">off</span>
echo WARNING<span style="color: #66cc66;">!</span>  This will install the ColdFusion MX Apache Connector.
echo Press Control<span style="color: #66cc66;">+</span>C <span style="color: #800080;">to</span> abort.
<span style="color: #0000FF;">pause</span>
SETLOCAL
PATH=..\..\runtime\jre\bin<span style="color: #008000; font-style: italic;">;%PATH%</span>
java <span style="color: #66cc66;">-</span>jar ..\..\runtime\lib\wsconfig.jar  <span style="color: #66cc66;">-</span>ws apache <span style="color: #66cc66;">-</span>bin <span style="color: #ff0000;">&quot;e:\\ms4w\Apache\bin\httpd.exe&quot;</span> <span style="color: #66cc66;">-</span>dir <span style="color: #ff0000;">&quot;e:\\ms4w\apache\conf&quot;</span> <span style="color: #66cc66;">-</span>map .cfm,.cfc,.cfml <span style="color: #66cc66;">-</span>coldfusion <span style="color: #66cc66;">-</span>v
ENDLOCAL</pre></div></div>

<p>11. Restart Apache and ColdFusion. Browse to <a href="http://127.0.0.1/cfide/administrator/index.cfm">http://127.0.0.1/cfide/administrator/index.cfm</a></p>
<p><strong>C. Installing Python2.4</strong><br />
1. Read Reference document from <a href="http://www.maptools.org/ms4w/index.phtml?page=README_INSTALL.html">maptools.org install site</a></p>
<p>2. Download Python2.4 from <a href="http://www.python.org/ftp/python/2.4/python-2.4.msi">http://www.python.org/ftp/python/2.4/python-2.4.msi</a>. Download mod_python from <a href="http://www.eng.lsu.edu/mirrors/apache/httpd/modpython/win/3.3.0b/mod_python-3.3.0b.win32-py2.4-Apache2.2.exe">mod_python-3.3.0b.win32-py2.4-Apache2.2.exe</a></p>
<p>3. Install Python2.4 in your root drive. (D:\)</p>
<p>4. Install mod_python-3.3.0b.win32-py2.4-Apache2.2.exe</p>
<p>5. Edit your Windows Environment Variables (System Variable: PATH) to include &#8220;D:\Python23&#8243;</p>
<p>6. Edit E:\ms4w\Apache\conf\httpd.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#For Python</span>
LoadModule python_module modules<span style="color: #000000; font-weight: bold;">/</span>mod_python.so
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>directory<span style="color: #000000; font-weight: bold;">&gt;</span>
	AddHandler python-program .py
	PythonHandler <span style="color: #7a0874; font-weight: bold;">test</span>
	PythonDebug On
<span style="color: #000000; font-weight: bold;">&lt;/</span>directory<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
ScriptInterpreterSource Registry
SetEnv PYTHONUNBUFFERED <span style="color: #000000;">1</span>
PassEnv PYTHONPATH</pre></div></div>

<p>7. Restart Apache and test from <a href="http://127.0.0.1/pytest/test.py">http://127.0.0.1/pytest/test.py</a>. If you see a &#8220;Hello World&#8221; web page from python then you are good to go. Sample python test page &#8220;test.py&#8221;:<br />
E:\wwwroot\pytest\test.py</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> mod_python <span style="color: #ff7700;font-weight:bold;">import</span> apache
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> handler<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>:
	req.<span style="color: black;">content_type</span> = <span style="color: #483d8b;">'text/plain'</span>
	req.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello World!&quot;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> apache.<span style="color: black;">OK</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/01/installing-ms4w-python24-coldfusion61/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

