Home TutorialsHow to How to: Setup Virtualenvwrapper on MacOS

How to: Setup Virtualenvwrapper on MacOS

by Atif Azad

For Python app developers, its a common practice to use virtual environments. Virtualenvwrapper is a tool to conveniently work with virtual environments. As the name implies, it is a wrapper over virtualenv. The following setup has been tested on MacOS Catalina however it should also work on other versions with a little or no modifications.

Setup time (approx.) 30 minutes.

Steps

  1. Install Homebrew, if you don’t have it already.

    There are other possibilities as well to install Python3 but I recommend installing it via Homebrew for cleaner installation and easier maintenance (upgrade etc).

    Command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  2. Install Python3

    Command: brew install python3

    pip3 also gets installed automatically with above command.

  3. Install Virtualenvwrapper

    Command: sudo -H pip3 install virtualenvwrapper

  4. In .zshrc (or bashrc), add following lines:

    export WORKON_HOME=$HOME/.virtualenvs
    export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
    export PROJECT_HOME=$HOME/Devel
    source /usr/local/bin/virtualenvwrapper.sh


    In your home directory, you’ll find one of the two; .zshrc or .bashrc depending on the shell you use. If there is no such file, please create one (again according to the shell you use).

    Please note that Mac Catalina uses Zsh by default.

  5. Load the new configuration

    Command: source ~/.zshrc
    or source ~/.bashrc

  6. Create a virtual environment

    You should be able to use following command without error:
    Command: mkvirtualenv test-env

    test-env should have been created and activated.

    PS: You can remove the test-env, if you don’t want to keep it, with command: rmvirtualenv test-env.

  7. Activate a virtual environment / Switch between virtual environments

    Command: workon <name-of-env>
    If you have test-env-1 and test-env-2 created, you can switch between these two using workon command.

  8. Deactivate the current virtual environment

    Command: deactivate

  9. Remove a virtual environment

    Command rmvirtualenv <name-of-env>

0 0 vote
Article Rating

You may also like

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy
0
Would love your thoughts, please comment.x
()
x