<?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>Patrick&#039;s playground &#187; auto-complete</title>
	<atom:link href="http://www.vankouteren.eu/blog/tag/auto-complete/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vankouteren.eu/blog</link>
	<description>Random thoughts, problems and solutions</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:53:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting IPython readline and auto-completion to work on Mac OS X</title>
		<link>http://www.vankouteren.eu/blog/2009/06/getting-ipython-readline-and-auto-completion-to-work-on-mac-os-x/</link>
		<comments>http://www.vankouteren.eu/blog/2009/06/getting-ipython-readline-and-auto-completion-to-work-on-mac-os-x/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 12:11:01 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[auto-complete]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[readline]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=98</guid>
		<description><![CDATA[It's taken me some time and a lot of web pages which tried to solve the readline support with all kinds of hacks, but finally I've been able to get readline support and auto-completion for IPython to work. As it can be quite confusing and hard to follow all posts, this will be a step-by-step [...]]]></description>
			<content:encoded><![CDATA[<p>It's taken me some time and a lot of web pages which tried to solve the readline support with all kinds of hacks, but finally I've been able to get readline support and auto-completion for IPython to work. As it can be quite confusing and hard to follow all posts, this will be a step-by-step approach to get things to work. Note that I've got it working on Mac OS X 10.5.7 Leopard. It is expected to work on Leopard at least. Other versions might not require the exact same solution.</p>
<p><span id="more-98"></span></p>
<p>If you don't already have IPython you can install it by opening a console and typing</p>
<pre>sudo easy_install ipython</pre>
<p>Mac OS X does include a readline functionality, but not 'the real one' gnureadline, because of a license issue. It can be manually installed, which we will do next. If you've not done so already, open a console and type</p>
<pre>sudo easy_install -f http://ipython.scipy.org/dist/ readline</pre>
<p>Type in your password and the readline functionality will be installed. Big joy you would think, but it's very well possible that it still doesn't work. Try for yourself by typing the following in your console:</p>
<pre>ipython</pre>
<p>IPython will start. Let's see if we can auto-complete here. First type</p>
<pre class="python"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span></pre>
<p>Now we've done an import and we will try to have auto-complete hint what we can do with it. In the next line type</p>
<pre class="python"><span style="color: #dc143c;">sys</span>.</pre>
<p>Press Tab directly after the dot. If IPython hints all types of functions preceded by sys. in a list, you're done with this tutorial. If your cursor just jumps, auto-complete doesn't work and you might want to execute the following steps.<br />
IPython has a file which is used to start it. We need to edit this file to tell where the readline module is installed.<br />
If you're still in IPython, close it by pressing CTRL+D and confirming (y). You are now back on the console again.<br />
The file which we are about to edit (done with Vim here) is a read-only file, so we need to sudo once again. Type the following</p>
<pre>sudo vim /usr/local/bin/ipython</pre>
<p>Enter your password and Vim will open a config file with just a few lines like</p>
<pre class="python"><span style="color: #808080; font-style: italic;">#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python</span>
<span style="color: #808080; font-style: italic;"># EASY-INSTALL-ENTRY-SCRIPT: 'ipython==0.9.1','console_scripts','ipython'</span>
__requires__ = <span style="color: #483d8b;">'ipython==0.9.1'</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pkg_resources <span style="color: #ff7700;font-weight:bold;">import</span> load_entry_point
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span>
   load_entry_point<span style="color: black;">&#40;</span><span style="color: #483d8b;">'ipython==0.9.1'</span>, <span style="color: #483d8b;">'console_scripts'</span>, <span style="color: #483d8b;">'ipython'</span><span style="color: black;">&#41;</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#41;</span></pre>
<p>First find the location of the egg directory of readline which you've just installed. It's probably something like /Library/Python/site-packages/readline-.egg<br />
I've installed the i386 readline module version 2.5.1, so my location is /Library/Python/2.5/site-packages/readline-2.5.1-py2.5-macosx-10.5-i386.egg<br />
We will need this location next.<br />
Go back to your console where the file is still opened.<br />
Leave the first two lines and the import sys line. The rest can be commented out.<br />
Now insert the following three lines after import sys:</p>
<pre class="python"><span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #483d8b;">'path to readline egg'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">import</span> IPython.<span style="color: black;">Shell</span>
IPython.<span style="color: black;">Shell</span>.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">mainloop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p>In my case, the ipython file looks as follows:</p>
<pre class="python"><span style="color: #808080; font-style: italic;">#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python</span>
<span style="color: #808080; font-style: italic;"># EASY-INSTALL-ENTRY-SCRIPT: 'ipython==0.9.1','console_scripts','ipython'</span>
<span style="color: #808080; font-style: italic;">#__requires__ = 'ipython==0.9.1'</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #808080; font-style: italic;">#from pkg_resources import load_entry_point</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #483d8b;">'/Library/Python/2.5/site-packages/readline-2.5.1-py2.5-macosx-10.5-i386.egg'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> IPython.<span style="color: black;">Shell</span>
IPython.<span style="color: black;">Shell</span>.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">mainloop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#sys.exit(</span>
<span style="color: #808080; font-style: italic;">#   load_entry_point('ipython==0.9.1', 'console_scripts', 'ipython')()</span>
<span style="color: #808080; font-style: italic;">#)</span></pre>
<p>Save and quit the file by typing</p>
<pre class="bash">:wq</pre>
<p>You're back at the command line again. Let's test the auto-complete. Again type</p>
<pre>ipython</pre>
<p>IPython will start. Let's see if we can auto-complete here. First type</p>
<pre class="python"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span></pre>
<p>Now we've done an import and we will try to have auto-complete hint what we can do with it. In the next line type</p>
<pre class="python"><span style="color: #dc143c;">sys</span>.</pre>
<p>Press Tab directly after the dot. If all went well Python hints all types of functions preceded by sys. in a list.</p>
<p><strong>Sites that helped me and / or might be useful for you:</strong></p>
<ul>
<li><a title="IPython on Mac OS X" href="http://hurley.wordpress.com/2008/11/15/ipython-on-mac-os-x/" target="_blank">IPython on Mac OS X</a></li>
<li><a title="Incredible Vehicle" href="http://incrediblevehicle.com/2009/06/11/readline-python-ipython-and-mac-os-x/" target="_blank">Incredible Vehicle</a></li>
<li><a title="Launchpad" href="https://bugs.launchpad.net/ipython/+bug/254023" target="_blank">Launchpad</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2009/06/getting-ipython-readline-and-auto-completion-to-work-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

