Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active February 19, 2023 05:47
Show Gist options
  • Save obfusk/dad7bec26d3b4fa39250fc3eccd60cc5 to your computer and use it in GitHub Desktop.
Save obfusk/dad7bec26d3b4fa39250fc3eccd60cc5 to your computer and use it in GitHub Desktop.
global venv

PEP 668 breaks --user

As a workaround, you can create a global venv that acts a lot like --user does now.

NB: this works for scripts that are part of the packages installed in the venv, but scripts that use e.g. #!/usr/bin/python3 will not be able to access the modules from the venv, only scripts called via ~/.venv/bin/python3 (or ~/.venv/bin/python, ~/.venv/bin/python3.11 etc.) will be able to access those.

Create venv

python3 -mvenv --system-site-packages --without-pip ~/.venv

Automatically use venv

Add this to your ~/.bashrc:

if [ -d ~/.venv/bin ] && [[ ":$PATH:" != *:"$HOME/.venv/bin":* ]]; then
  PATH="$HOME/.venv/bin:$PATH"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment