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.
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:
Next, we need to install Homebrew. Open Terminal and run this line of command:
ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
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:
Save and quit the TextEditor and also the Terminal. Now you are done with Homebrew installing.
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:
Create virtual environment
Notice that, you already have pyenv when installing Python3. Now we can create a new virtual environment:
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:
And to deactive it: