Python 3 & Pyenv Quick Start...

Typical scenario

Me - Installing Python 3 in a OS X box is really easy, you just open your terminal and type brew install python3.
You - Oh wait, what is brew? What is OS X box?
Me - Oh my bad, let me explain. OS X stands for Operating System Ten and I’m referring to your Mac computer. So OS X is your Mac. Brew is the command for Homebrew which is a package manager for installing OS X applications, most of those applications are CLI apps.
You - Uh? CLI?
Me - Oh my bad again… CLI stands for Command Line Interface which is a long name for your terminal. We just called it terminal, shell, or CLI.
You - Terminal???
Me - Yeah the terminal… that black window that has a lot of text that is difficult to understand.

We can now see how messy a simple Python 3 installation can get for a person that just want to start learning how to code. The purpose of this short tutorial is to ease the Python 3 installation and to make Python 3 global in your system.

Table of contents


For this post I am assuming the following:

  • You have no experience whatsoever or very little with any programing languages.
  • You have some knowledge how to navigate around your computer.
  • You want to learn to write Python code.

Scope of the tutorial

OS X ships with Python 2 and is used by the operating system to perform tasks in your computer. We don’t want to touch that installation of Python for two main reasons. One - is part of the Mac operating system, and two - It is recommended to do software development with Python 3 since Python 2 will be no longer supported by 2020. So our goal is to install globally Python 3 in your Mac.

Lets get our hands dirty - Installing Hombrew

First things first, we need to install Homebrew in your system if you don’t already have it. So let’s go to Homebrew’s and copy the command that appears below Install Homebrew or you can copy the command bellow.

 $ /usr/bin/ruby -e "$(curl -fsSL" <br>

After you have copied the command open your terminal. Now, there are several ways you can open the terminal. You can use your mouse to browse your system to open applications, or we can rather make the use of key strokes or key shortcuts. So let’s start learning how to use our keyboard other than typing an email. Our first command will open the Spotlight Search. Press cmd+space and the Spotlight Search will open.
You - Wait… What? What is cmd+space?
Me - cmd is your command key next to the space bar key and space is the space bar key. So you need to simultaneously press cmd_space. Now type the word terminal in the Spotlight Search input and press Enter. Your terminal window should be in your screen. Your terminal should look like this…

 $ |

The $ is the terminal prompt. That $ with the blinking vertical cursor means that the terminal is waiting for you to type a command. So let’s paste the command you copied from the Homebrew’s web page. To paste the command you can press cmd+v. By now you should understand what cmd+v means, GOOD! Once the command is pasted press Enter. You should see a bunch of text and progress bars in the terminal window. That means that Homebrew’s is getting installed. You know that the installation is finished when you see back the $. Now you have Homebrew’s installed in your computer.

Installing Pyenv

Pyenv is a Python Version Manager that lets you easily switch between multiple versions of Python. It’s simple, unobtrusive, and is a tool that does one thing well. I could rather direct you to the pyenv GitHub repo and let you figure out how to install pyenv, but for now I’m going to list all the necessary commands for installing pyenv.
You - GitHub?
Me - Well… I know that I’m throwing a bunch of technical terms at you that you don’t understand, but bear with me through this installation. And trust me, knowing what GitHub is or does is not relevant right now, later you can learn what GitHub is. As you grow in knowledge, you will learn all sort of technologies and you will be able to perform installations like this one on your own by just reading documentation. So let’s install pyenv!

 $ brew update
 $ brew install pyenv
 $ echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Just in case one of you is using zsh, please notice that you need to change .bashrc in the last command for .zshrc. The same will happen with the next command.

 $ source ~/.bashrc
 $ pyenv install 3.6.1
 $ pyenv global 3.6.1

Now close your terminal by cmd+q and open it again.

 $ python --version
 Python 3.6.1

CONGRATULATIONS! Now your are ready to utilize Python 3 as the global Python version in your system and start learning Python code. If you have any question please leave a comment below.