|
1 | | -<!DOCTYPE html> |
2 | | -<html> |
3 | | - <head> |
4 | | - |
5 | | - |
6 | | - <meta charset="utf-8"> |
7 | | - <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
8 | | - <meta name="viewport" content="width=device-width, initial-scale=1"> |
9 | | - |
10 | | - <meta property="og:title" content="How to use Readline in the Python REPL on MacOS?" /> |
11 | | - <meta property="og:type" content="website" /> |
12 | | - <meta property="og:url" content="https://www.explodinglabs.com/posts/" /> |
13 | | - <meta property="og:image" content="https://www.explodinglabs.com/posts/assets/opengraph.png" /> |
14 | | - <meta property="og:image:secure_url" content="https://www.explodinglabs.com/posts/assets/opengraph.png" /> |
15 | | - <meta property="og:image:type" content="image/png" /> |
16 | | - <meta property="og:image:width" content="1200" /> |
17 | | - <meta property="og:image:height" content="630" /> |
18 | | - <meta property="og:image:alt" content="Composition in architecture" /> |
19 | | - |
20 | | - <link rel="stylesheet" href="/posts/main.css"> |
21 | | - <link rel="alternate" type="application/rss+xml" title="Exploding Labs Blog" href="https://explodinglabs.com/posts/feed.xml"> |
22 | | - <link rel="author" href="https://plus.google.com/u/0/110235318020270619650?rel=author" /> |
23 | | - |
24 | | - <link rel="icon" type="image/png" href="/assets/favicon-16x16.png?v=2" sizes="16x16"> |
25 | | - <link rel="icon" type="image/png" href="/assets/favicon-32x32.png?v=2" sizes="32x32"> |
26 | | - <link rel="icon" type="image/png" href="/assets/favicon-96x96.png?v=2" sizes="96x96"> |
27 | | - |
28 | | - <link rel="apple-touch-icon" sizes="120x120" href="/assets/apple-touch-icon-120x120.png?v=2"> |
29 | | - <link rel="apple-touch-icon" sizes="152x152" href="/assets/apple-touch-icon-152x152.png?v=2"> |
30 | | - <link rel="apple-touch-icon" sizes="167x167" href="/assets/apple-touch-icon-167x167.png?v=2"> |
31 | | - <link rel="apple-touch-icon" sizes="180x180" href="/assets/apple-touch-icon-180x180.png?v=2"> |
32 | | - |
33 | | - |
34 | | - |
35 | | - <!-- Begin Jekyll SEO tag v2.7.1 --> |
36 | | -<title>How to use Readline in the Python REPL on MacOS? | Exploding Labs Blog</title> |
37 | | -<meta name="generator" content="Jekyll v4.2.0" /> |
38 | | -<meta property="og:title" content="How to use Readline in the Python REPL on MacOS?" /> |
39 | | -<meta name="author" content="Beau Barker" /> |
40 | | -<meta property="og:locale" content="en_AU" /> |
41 | | -<meta name="description" content="A programming blog." /> |
42 | | -<meta property="og:description" content="A programming blog." /> |
43 | | -<link rel="canonical" href="https://explodinglabs.com/posts/python/mac-repl-readline" /> |
44 | | -<meta property="og:url" content="https://explodinglabs.com/posts/python/mac-repl-readline" /> |
45 | | -<meta property="og:site_name" content="Exploding Labs Blog" /> |
46 | | -<meta property="og:image" content="https://explodinglabs.com/posts/assets/python-wide.png" /> |
47 | | -<meta property="og:type" content="article" /> |
48 | | -<meta property="article:published_time" content="2018-06-20T00:00:00+00:00" /> |
49 | | -<meta name="twitter:card" content="summary_large_image" /> |
50 | | -<meta property="twitter:image" content="https://explodinglabs.com/posts/assets/python-wide.png" /> |
51 | | -<meta property="twitter:title" content="How to use Readline in the Python REPL on MacOS?" /> |
52 | | -<script type="application/ld+json"> |
53 | | -{"description":"A programming blog.","mainEntityOfPage":{"@type":"WebPage","@id":"https://explodinglabs.com/posts/python/mac-repl-readline"},"image":"https://explodinglabs.com/posts/assets/python-wide.png","headline":"How to use Readline in the Python REPL on MacOS?","dateModified":"2025-07-15T23:16:53+00:00","datePublished":"2018-06-20T00:00:00+00:00","url":"https://explodinglabs.com/posts/python/mac-repl-readline","author":{"@type":"Person","name":"Beau Barker"},"@type":"BlogPosting","@context":"https://schema.org"}</script> |
54 | | -<!-- End Jekyll SEO tag --> |
55 | | - |
56 | | - </head> |
57 | | - <body> |
58 | | - |
59 | | - |
60 | | - |
61 | | - |
62 | | -<nav> |
63 | | - <div id="logo"> |
64 | | - <a href="/posts/">Exploding Labs Posts<!--img src="/posts/assets/composed.png" /--></a> |
65 | | - </div> |
66 | | - <div id="categories"> |
67 | | - <!--a href="/posts/">All</a> |
68 | | - <span>(73)</span--> |
69 | | - |
70 | | - <a href="/posts/haskell/">Haskell</a> |
71 | | - <span>(2)</span> |
72 | | - |
73 | | - <a href="/posts/jsonrpc/">JSON-RPC</a> |
74 | | - <span>(16)</span> |
75 | | - |
76 | | - <a href="/posts/python/">Python</a> |
77 | | - <span>(19)</span> |
78 | | - |
79 | | - <a href="/posts/airflow/">Airflow</a> |
80 | | - <span>(6)</span> |
81 | | - </div> |
82 | | -</nav> |
83 | | - |
84 | | -<main> |
85 | | - |
86 | | - <article itemscope itemtype="http://schema.org/BlogPosting"> |
87 | | - <header> |
88 | | - <h1>How to use Readline in the Python REPL on MacOS?</h1> |
89 | | - <div class="post-meta"> |
90 | | - <time datetime="2018-06-20T00:00:00+00:00" itemprop="datePublished"> |
91 | | - Beau Barker, <time>Jun 20, 2018</time>. |
92 | | - |
93 | | - Updated <time>Jul 15, 2025</time>. |
94 | | - |
95 | | - <a href="https://github.com/explodinglabs/posts/edit/main/docs/_posts/python/2018-06-20-mac-repl-readline.markdown"> |
96 | | - ✎ |
97 | | - </a> |
98 | | - </time> |
99 | | - </div> |
100 | | - </header> |
101 | | - <div class="wide-logos"> |
102 | | - <p><img src="/assets/python.png" alt="python" /></p> |
| 1 | +<div class="wide-logos"> |
| 2 | + <p><img src="/posts/assets/python.png" alt="python" /></p> |
103 | 3 | </div> |
104 | 4 |
|
105 | 5 | <div id="intro"> |
106 | 6 | <p>How to use readline in the Python interactive interpreter on Mac.</p> |
107 | 7 | </div> |
108 | 8 |
|
109 | 9 | <p>Install the gnureadline Python package:</p> |
| 10 | + |
110 | 11 | <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pip <span class="nb">install </span>gnureadline |
111 | 12 | </code></pre></div></div> |
112 | 13 |
|
113 | 14 | <p>Create a <code class="language-plaintext highlighter-rouge">~/.pythonstartup.py</code> script:</p> |
| 15 | + |
114 | 16 | <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">atexit</span> |
115 | 17 | <span class="kn">import</span> <span class="nn">gnureadline</span> <span class="k">as</span> <span class="n">readline</span> |
116 | 18 | <span class="kn">import</span> <span class="nn">logging</span> |
@@ -142,26 +44,16 @@ <h1>How to use Readline in the Python REPL on MacOS?</h1> |
142 | 44 | </code></pre></div></div> |
143 | 45 |
|
144 | 46 | <p>Set the <code class="language-plaintext highlighter-rouge">PYTHONSTARTUP</code> env var:</p> |
| 47 | + |
145 | 48 | <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">PYTHONSTARTUP</span><span class="o">=</span><span class="nv">$HOME</span>/.pythonstartup.py |
146 | 49 | </code></pre></div></div> |
147 | 50 |
|
148 | 51 | <p>Start the Python REPL.</p> |
| 52 | + |
149 | 53 | <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>python |
150 | 54 | Python 3.6.5 <span class="o">(</span>default, Mar 29 2018, 15:37:32<span class="o">)</span> |
151 | 55 | <span class="o">[</span>GCC 4.2.1 Compatible Apple LLVM 9.0.0 <span class="o">(</span>clang-900.0.39.2<span class="o">)]</span> on darwin |
152 | 56 | Type <span class="s2">"help"</span>, <span class="s2">"copyright"</span>, <span class="s2">"credits"</span> or <span class="s2">"license"</span> <span class="k">for </span>more information. |
153 | 57 | Booted pythonstartup.py. |
154 | 58 | <span class="o">>>></span> |
155 | 59 | </code></pre></div></div> |
156 | | - |
157 | | - <footer> |
158 | | - <a href="/python">More Python posts</a> |
159 | | - </footer> |
160 | | - </article> |
161 | | - |
162 | | - |
163 | | - |
164 | | -</main> |
165 | | - |
166 | | - </body> |
167 | | -</html> |
0 commit comments