<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Akash Vacher's blog]]></title><description><![CDATA[A tech enthusiast who enjoys problem-solving, programming, and trying out new Linux distros]]></description><link>https://www.akashvacher.com</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Apr 2026 21:06:07 GMT</lastBuildDate><atom:link href="https://www.akashvacher.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to make pypy work on macOS Big Sur]]></title><description><![CDATA[Recently, I ran into a couple of situations where I knew that having a faster python interpreter (say, pypy) could speed up the execution for the python programs drastically.
So, I fired up the terminal and typed in brew install pypy3.
To my surprise...]]></description><link>https://www.akashvacher.com/how-to-make-pypy-work-on-macos-big-sur</link><guid isPermaLink="true">https://www.akashvacher.com/how-to-make-pypy-work-on-macos-big-sur</guid><category><![CDATA[Python]]></category><category><![CDATA[Docker]]></category><category><![CDATA[macOS]]></category><category><![CDATA[mac]]></category><category><![CDATA[macbook]]></category><dc:creator><![CDATA[Akash Vacher]]></dc:creator><pubDate>Sun, 17 Jan 2021 10:52:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1610880279427/d1-5rREQ9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Recently, I ran into a couple of situations where I knew that having a faster python interpreter (say, <a target="_blank" href="https://www.pypy.org/">pypy</a>) could speed up the execution for the python programs drastically.</p>
<p>So, I fired up the terminal and typed in <code>brew install pypy3</code>.</p>
<p>To my surprise, brew took over 10 minutes(!) and then <em>failed</em> to install pypy3 with the following cryptic error:</p>
<pre><code>==&gt; Summary
🍺  /usr/local/akash/Homebrew/Cellar/tcl-tk/<span class="hljs-number">8.6</span><span class="hljs-number">.11</span>: <span class="hljs-number">3</span>,<span class="hljs-number">041</span> files, <span class="hljs-number">34.4</span>MB, built in <span class="hljs-number">10</span> minutes <span class="hljs-number">34</span> seconds
==&gt; Installing pypy3 dependency: pypy
==&gt; /<span class="hljs-keyword">private</span>/tmp/pypy<span class="hljs-number">-20210117</span><span class="hljs-number">-11515</span><span class="hljs-number">-1</span>ie0xew/pypy2<span class="hljs-number">.7</span>-v7<span class="hljs-number">.3</span><span class="hljs-number">.3</span>-src/bootstrap/bin/pypy /<span class="hljs-keyword">private</span>/tmp/pypy<span class="hljs-number">-20210117</span><span class="hljs-number">-11515</span><span class="hljs-number">-1</span>ie0xew/pypy2<span class="hljs-number">.7</span>-v7<span class="hljs-number">.3</span><span class="hljs-number">.3</span>-src/rpython/bin/rpython -Oji
Last <span class="hljs-number">15</span> lines <span class="hljs-keyword">from</span> /Users/avacher/Library/Logs/Homebrew/pypy/<span class="hljs-number">01.</span>pypy:
  File <span class="hljs-string">"/private/tmp/pypy-20210117-11515-1ie0xew/pypy2.7-v7.3.3-src/rpython/translator/goal/translate.py"</span>, line <span class="hljs-number">327</span>, in main
    debug(<span class="hljs-literal">True</span>)
  File <span class="hljs-string">"/private/tmp/pypy-20210117-11515-1ie0xew/pypy2.7-v7.3.3-src/rpython/translator/goal/translate.py"</span>, line <span class="hljs-number">280</span>, in debug
    pdb_plus_show.start(tb)
  File <span class="hljs-string">"/private/tmp/pypy-20210117-11515-1ie0xew/pypy2.7-v7.3.3-src/rpython/translator/tool/pdbplus.py"</span>, line <span class="hljs-number">442</span>, in start
    <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params">*args</span>)
  <span class="hljs-title">File</span> "/<span class="hljs-title">private</span>/<span class="hljs-title">tmp</span>/<span class="hljs-title">pypy</span>-20210117-11515-1<span class="hljs-title">ie0xew</span>/<span class="hljs-title">pypy2</span>.7-<span class="hljs-title">v7</span>.3.3-<span class="hljs-title">src</span>/<span class="hljs-title">rpython</span>/<span class="hljs-title">translator</span>/<span class="hljs-title">tool</span>/<span class="hljs-title">pdbplus</span>.<span class="hljs-title">py</span>", <span class="hljs-title">line</span> 25, <span class="hljs-title">in</span> <span class="hljs-title">post_mortem</span>
    <span class="hljs-title">self</span>.<span class="hljs-title">interaction</span>(<span class="hljs-params">t.tb_frame, t</span>)
  <span class="hljs-title">File</span> "/<span class="hljs-title">private</span>/<span class="hljs-title">tmp</span>/<span class="hljs-title">pypy</span>-20210117-11515-1<span class="hljs-title">ie0xew</span>/<span class="hljs-title">pypy2</span>.7-<span class="hljs-title">v7</span>.3.3-<span class="hljs-title">src</span>/<span class="hljs-title">bootstrap</span>/<span class="hljs-title">lib</span>-<span class="hljs-title">python</span>/2.7/<span class="hljs-title">pdb</span>.<span class="hljs-title">py</span>", <span class="hljs-title">line</span> 210, <span class="hljs-title">in</span> <span class="hljs-title">interaction</span>
    <span class="hljs-title">self</span>.<span class="hljs-title">cmdloop</span>(<span class="hljs-params"></span>)
  <span class="hljs-title">File</span> "/<span class="hljs-title">private</span>/<span class="hljs-title">tmp</span>/<span class="hljs-title">pypy</span>-20210117-11515-1<span class="hljs-title">ie0xew</span>/<span class="hljs-title">pypy2</span>.7-<span class="hljs-title">v7</span>.3.3-<span class="hljs-title">src</span>/<span class="hljs-title">bootstrap</span>/<span class="hljs-title">lib</span>-<span class="hljs-title">python</span>/2.7/<span class="hljs-title">cmd</span>.<span class="hljs-title">py</span>", <span class="hljs-title">line</span> 109, <span class="hljs-title">in</span> <span class="hljs-title">cmdloop</span>
    <span class="hljs-title">self</span>.<span class="hljs-title">preloop</span>(<span class="hljs-params"></span>)
  <span class="hljs-title">File</span> "/<span class="hljs-title">private</span>/<span class="hljs-title">tmp</span>/<span class="hljs-title">pypy</span>-20210117-11515-1<span class="hljs-title">ie0xew</span>/<span class="hljs-title">pypy2</span>.7-<span class="hljs-title">v7</span>.3.3-<span class="hljs-title">src</span>/<span class="hljs-title">rpython</span>/<span class="hljs-title">translator</span>/<span class="hljs-title">tool</span>/<span class="hljs-title">pdbplus</span>.<span class="hljs-title">py</span>", <span class="hljs-title">line</span> 29, <span class="hljs-title">in</span> <span class="hljs-title">preloop</span>
    <span class="hljs-title">raise</span> <span class="hljs-title">NoTTY</span>(<span class="hljs-params"><span class="hljs-string">"Cannot start the debugger when stdout is captured."</span></span>)
<span class="hljs-title">NoTTY</span>: <span class="hljs-title">Cannot</span> <span class="hljs-title">start</span> <span class="hljs-title">the</span> <span class="hljs-title">debugger</span> <span class="hljs-title">when</span> <span class="hljs-title">stdout</span> <span class="hljs-title">is</span> <span class="hljs-title">captured</span>.

<span class="hljs-title">Do</span> <span class="hljs-title">not</span> <span class="hljs-title">report</span> <span class="hljs-title">this</span> <span class="hljs-title">issue</span> <span class="hljs-title">to</span> <span class="hljs-title">Homebrew</span>/<span class="hljs-title">brew</span> <span class="hljs-title">or</span> <span class="hljs-title">Homebrew</span>/<span class="hljs-title">core</span>!</span>
</code></pre><p>Great. That doesn't help me at all.</p>
<p>After a bit of futile Googling, and searching the <a target="_blank" href="https://foss.heptapod.net/pypy/pypy/-/issues">pypy bug tracker</a> without getting anything directly related to my issue, it suddenly hit me:</p>
<blockquote>
<p>I don't necessarily need to install pypy, I just want the ability to run my python code using the pypy interpreter!</p>
</blockquote>
<p>Now, if you are puzzled and asking how can I execute pypy without ever installing pypy in the first place, let me tell you a little bit about <a target="_blank" href="https://www.docker.com/">Docker</a>.</p>
<h3 id="docker-101">🐳 Docker 101</h3>
<p>A simple overview of Docker from the <a target="_blank" href="https://docs.docker.com/get-started/overview/">official docs</a> :</p>
<blockquote>
<p>Docker provides the ability to package and run an application in a loosely isolated environment called a container.</p>
<p>Containers are lightweight because they don’t need the extra load of a hypervisor, but run directly within the host machine’s kernel.</p>
</blockquote>
<p>For our purposes, if we can get a pypy interpreter running in a docker container, it should theoretically work irrespective of the Mac OS version and/or underlying CPU architecture (I'm looking at you <a target="_blank" href="https://www.apple.com/in/mac/m1/">Apple M1 </a>).</p>
<p>In a nutshell - docker can be used to run applications reliably on multiple different operating systems without the need to <em>actually</em> install anything on the underlying operating system!</p>
<p>The only prerequisite to running docker containers is to first <a target="_blank" href="https://docs.docker.com/engine/install/">install Docker</a>.</p>
<h3 id="running-on">Running 🐍 on 🐳</h3>
<p>At this point, I have 2 choices: I either build a docker image from scratch and include pypy3 inside it, or I just go and search for an already built readily available Docker image.</p>
<p>Thankfully, I didn't have to go very far as a quick web search later I reached the <a target="_blank" href="https://hub.docker.com/_/pypy">official Docker image page for pypy</a> which had the exact command that I was looking for 😄</p>
<pre><code>$ docker run -it --rm -v <span class="hljs-string">"$PWD"</span><span class="hljs-symbol">:/usr/src/myapp</span> -w /usr/src/myapp <span class="hljs-symbol">pypy:</span><span class="hljs-number">3</span> pypy3 your-daemon-<span class="hljs-keyword">or</span>-script.py
</code></pre><p>Note that the first time you run this command, it'll be a bit slow as it will download the necessary Docker image layer files before it can start the docker container. 
Subsequent runs will not need to repeat this download and will only spend a minuscule amount of time in starting the docker container.</p>
<p>I ran the command above and timed the execution to see if pypy made a difference in the execution time or not:</p>
<pre><code>akash <span class="hljs-keyword">in</span> ~<span class="hljs-regexp">/code/programs</span>
$ time python3 slow.py 
All Done!
python3 slow.py  <span class="hljs-number">84.38</span>s user <span class="hljs-number">1.83</span>s system <span class="hljs-number">93</span>% cpu <span class="hljs-number">1</span><span class="hljs-symbol">:</span><span class="hljs-number">32.07</span> total

akash <span class="hljs-keyword">in</span> ~<span class="hljs-regexp">/code/programs</span>
$ time docker run -it --rm -v <span class="hljs-string">"$PWD"</span><span class="hljs-symbol">:/usr/src/myapp</span> -w /usr/src/myapp <span class="hljs-symbol">pypy:</span><span class="hljs-number">3</span> pypy3 slow.py 
All Done!
docker run -it --rm -v <span class="hljs-string">"$PWD"</span><span class="hljs-symbol">:/usr/src/myapp</span> -w /usr/src/myapp <span class="hljs-symbol">pypy:</span><span class="hljs-number">3</span> pypy3   <span class="hljs-number">0</span>.<span class="hljs-number">03</span>s user <span class="hljs-number">0</span>.<span class="hljs-number">07</span>s system <span class="hljs-number">0</span>% cpu <span class="hljs-number">25.782</span> total
</code></pre><p>Result: <strong>1m 32s</strong> execution time down to <strong>~26s</strong> ⚡</p>
<p>Looks like we achieved what we set out to do.</p>
<h3 id="additional-notes">Additional notes</h3>
<p>The command to run the pypy container is long and definitely not easy to remember, so I added an alias for it by appending this line to my .zshrc file:</p>
<pre><code><span class="hljs-built_in">alias</span> pypy=<span class="hljs-string">"docker run -it --rm -v "</span><span class="hljs-variable">$PWD</span><span class="hljs-string">":/usr/src/myapp -w /usr/src/myapp pypy:3 pypy3"</span>
</code></pre><p>I just went ahead and got pypy3 as my python programs were written for python3. If for some reason you wished to get pypy for python2 instead, your docker run command would look like this instead:</p>
<pre><code>$ docker run -it --rm -v <span class="hljs-string">"$PWD"</span><span class="hljs-symbol">:/usr/src/myapp</span> -w /usr/src/myapp <span class="hljs-symbol">pypy:</span><span class="hljs-number">2</span> pypy your-daemon-<span class="hljs-keyword">or</span>-script.py
</code></pre><h3 id="conclusion">Conclusion</h3>
<p>Docker is awesome.</p>
<p>The best part about running a command-line application via docker is that the user experience is almost identical to that of a natively installed CLI as the docker container start time (which is spent at every execution) is negligible for most use cases.</p>
<p>Hence the fact that docker is working under the hood becomes transparent.</p>
]]></content:encoded></item></channel></rss>