Skip to content

Instantly share code, notes, and snippets.

@fpopic
Last active January 4, 2024 12:04
Show Gist options
  • Save fpopic/4c88eaa18d5ea7b5b2aef3bfd86667b6 to your computer and use it in GitHub Desktop.
Save fpopic/4c88eaa18d5ea7b5b2aef3bfd86667b6 to your computer and use it in GitHub Desktop.

Use custom Python virtual environment

In order to not use System Python installation, we can use custom virtual environment tools (e.g. virtualenv, pyenv, ...) that copy and isolate System Python installation into project folder so that installation of custom packages are done per project/repository basis.

  • Install virtualenv (brew install virtualenv)

    cd some-python-gitlab-repo
    
    # create virtual environment
    virtualenv --python=python3.8.7 venv
    
    # activate virtual environment (in terminal you should see (venv) indicator in path)
    source venv/bin/activate
    
    # ... now you can do stuff in your isolated python virtual environment ... 
    
    # deactivates virtual environment
    deactivate
  • Install direnv

    • Append to ~.zshrc
      eval "$(direnv hook zsh)"
    • Create ~/.config/direnv/config.toml so that cd within defined prefix automatically loads .env file
      [whitelist]
      prefix = [ "/Users/<<lastf>>/Projects/gitlab/umusic" ]
      Replace <<lastf>> with UMG user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment