Installing specific version of Python on macOS using home brew

Recently, I was working on some code that required Python 3.6. Although, it would probably run on newer versions of Python, I did not want to take any chances. I wanted to run it on Python 3.6. Normally, I would use a Docker container to ensure a reproducible environment. However, Docker imposes its own complexities when it comes to integrating with IDEs such as Pycharm. A common issue is debugging code when its runtime environment is inside a Docker container. IDEs usually don’t make it easy to create a breakpoint in the IDE and have the code run inside a Docker container. However, if the interpreter and the dependencies are on your host OS, it is easy to set breakpoints and debug code in Pycharm.

Getting back to my issue, I typically use Homebrew on macOS to install packages such as Python. It is a fantastic package manager and I have used it for a very long time now. However, it lacks the feature to install a specific version of a package. In this case, I wanted to install the latest Python 3.6 on my macOS. The only problem was that Homebrew had updated Python to 3.7 and so there wasn’t an easy way to have it install 3.6.

After a bit of digging around, I remembered that Homebrew uses a git repository to store all of its formulae. So, it was a matter of finding the correct Git SHA where the Homebrew maintainers had last updated Python 3.6 and using it to install Python.

Here are the steps I took to install Python 3.6 on macOS using Homebrew and a bit of Git.

First, unlink existing Python

brew unlink python

Next, install Python using the following command

brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

Here, f2a764ef944b1080be64bd88dca9a1d80130c558 is the Git SHA where I saw the last Python 3.6 update take place in the commit history.

If you’re interested, check out /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula. This is where all the Homebrew formulae live.

10 easy steps to build MicroPython on macOS for ESP8266

Python Programming Language

I have been playing around with MicroPython for a while now. I enjoy writing straight up C/C++ code but MicroPython has brought the ease of Python to embedded platforms especially ESP8266. ESP8266 and MicroPython make a killer combo.

I’ve written about the ESP8266 and built a couple projects with it already. I’ve built a WiFi temperature sensor using the ESP8266 board that publishes the temperature over MQTT to a central data logging server. It’s a fun project.

Continue reading “10 easy steps to build MicroPython on macOS for ESP8266”

Solution to Pick Peak problem on Codewars

Python Programming Language

Codewars is an interesting website for enhancing your coding skills. I have been playing around with the site for a while trying to get better at Python. I came across the “Pick Peak” problem on codewars that I found very interesting. In this post I’ll take you guys through the Solution to Pick Peak problem on Codewars. The ‘Pick Peak’ problem was fun and interesting. Here’s the problem.

Continue reading “Solution to Pick Peak problem on Codewars”