Transitioning to python3.5 in MacOS

Ankit Mittal
pyankit
Published in
2 min readAug 28, 2016

I have completely shifted to python3, apart from some ad hoc scripts that are used rarely. Surprisingly my transition (and our company’s full codebase) was smoother and easier than what I expected. There was no critical third party library that we were using and did not support python3. There were one odd easily replaceable Django apps which were kicked out without any trouble.

When we made this decision of transition there were multiple apprehensions, fears as python3 was sort of a completely unknown territory. The easiest way to kill those fears were to face them, ie install python3 on my development machine and try to play around with this. Try to use python3 with our python projects and sort of see how deep troubles are.

There are small differences in the way you can set up python dev environment for python3.5 compared to python2.7. If you are still on python2.7 just follow these 5 steps (with a broadband, should take less than 20 minutes) to get a working python3 environment on mac.

Step 1: Make sure you have generic utilities on mac — Homebrew, zsh (or any advanced shell), xcode command line utilities.

Step 2: Install python3.5 from python.org. Do not make python3.5 as default python on your machine. Since that is the default version shipped with mac, I suggest you keep it that way. Also, There might be some applications which depend on python2.7 implicitly.Once you do this, running python on your terminal will still open old python. To run python 3.5 shell or any script use command `python3`.

Step 3: Installing a package manager — pip works fine for most purposes. However, if you have much of the data sciency work, look out for Anaconda. Coming back to pip, you don’t need to install pip as it gets shipped with python3.5. However, you may have to upgrade it to a newer version to get rid of an annoying warning message.

Step 4: Installing virtualenv — Good news, you wont even need to install virtualenv. Python3.5 ships out with a command line utility called `pyvenv`, which you can use to create virtual environments for your machine. If you are not using virtual environments, I would really encourage you for using them as you will not have to bother switching between py2/py3 as, if you have a virtual environment created from py3, `python` keyword would mean python3 when that virtualenv is activated.

Step 5: Your python 3 setup is ready. Go fire up you IDE/vi or whatever and start kicking ass.

The road to python3 is much less tricky than what it seems.

--

--