<?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/category/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>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>
	</channel>
</rss>

