Install Python3, virtual environment on Mac OS X

This article will explain how to install Python3 and virtual environment with virtualenv on Mac OS X. Normally, your Mac installed Python 2.7 already, you could remove it or keep both of them.

Install Xcode

Before starting, make sure your Mac installed Xcode already. If not you can get it from Apple Store.

Next, we install Command line of Xcode through bellow command:

xcode-select –install

Install Homebrew

Next, we need to install Homebrew. Open Terminal and run this line of command:

ruby -e “$(curl -fsSL”

It will take a few minutes. After finishing, we need to export Homebrew to PATH environment variable. Create ~/.bash_profile or just open if it already existed, and append this line to file:

export PATH=/usr/local/bin:$PATH

Save and quit the TextEditor and also the Terminal. Now you are done with Homebrew installing.

Install Python3

It is quite easy to install Python3 now. Just reopen Terminal and use brew command in a way like that:

brew install python3

After things are done, you can check the version of Python by bellow line:

python3 –version

Create virtual environment

Notice that, you already have pyenv when installing Python3. Now we can create a new virtual environment:

pyvenv myenv

This command creates the new folder named myenv inside current folder. So that if you want to create new virtual environment in a specific folder, please free to do it.

To active the new environment:

source myenv/bin/activate

And to deactive it:


Leave a Reply

Your email address will not be published. Required fields are marked *