How to install a python virtual environment on a mac

Virtual environments are isolated working copies of python, which allow you to have different projects environments for each of your projects. Which prevents changes in one project affecting others.

1. Install Xcode

2. Open a terminal window

3. Install Command Line Tools of Xcode

xcode-select ––install

4. Install Homebrew

ruby -e \
“$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

5. Install python3

brew install python3

Run the below command to verify your python version.

python3 ––version

To begin executing python commands, execute the command below.

python3

6. Install virtualenv and virtualenvwrapper

pip3 install virtualenv virtualenvwrapper

7. Create a folder to store virtual environments

cd ~/
mkdir .virtualenvs

8. Setup virtualenvwrapper by inserting the following at the bottom of .bash_profile

export WORKON_HOME=~/.virtualenvs 
# point to .virtualenvs directory created above

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 
# make sure this is the location of which the python version 
# you are using is located [which python3] should 
# give you the location for python3

export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv

export VIRTUALENVWRAPPER_VIRTUALENV_ARGS=’––no-site-packages’

source /usr/local/bin/virtualenvwrapper.sh

9. Reload your .bash_profile to reflect changes

. ~/.bash_profile

10. Create a new virtualenv

mkvirtualenv env_name

Now you are inside of your virtual env. You can confirm this by checking to see if you see your env_name inside parenthesis to the left of your command prompt

To deactivate execute the below command.

deactivate
To activate a virtualenv execute the below command.
workon env_name

Still have issues? Contact us and we will walk you through it step by step.

About the author