Skip to content

Instantly share code, notes, and snippets.

@tho
Created August 12, 2017 16:42
Show Gist options
  • Save tho/0931d16a69da7372fee3f67911d46fc7 to your computer and use it in GitHub Desktop.
Save tho/0931d16a69da7372fee3f67911d46fc7 to your computer and use it in GitHub Desktop.
Python Virtual Environments

Python 2

  • Installing and setting up packages

      pip2 install virtualenv virtualenvwrapper
    
      # ~/.profile
      if command -v virtualenvwrapper.sh >/dev/null; then
          export WORKON_HOME=$HOME/.virtualenvs
          export PROJECT_HOME=$HOME/src
          VIRTUALENVWRAPPER_PYTHON=$(command -v python2)
          VIRTUALENVWRAPPER_VIRTUALENV=$(command -v virtualenv)
          export VIRTUALENVWRAPPER_PYTHON VIRTUALENVWRAPPER_VIRTUALENV
          source "$(command -v virtualenvwrapper.sh)"
      fi
    
  • Creating a virtual environment via virtualenv

      virtualenv <DIR>
      source <DIR>/bin/activate
    
  • Creating a virtual environment via virtualenvwrapper

      mkvirtualenv <NAME>
    

Python 3

  • Creating a virtual environment

      python3 -m venv <DIR>
      source <DIR>/bin/activate
    

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment