Skip to content

Instantly share code, notes, and snippets.

@thomashollier
Last active February 10, 2024 02:44
Show Gist options
  • Save thomashollier/78fcb8649fa6b8c1435607b968d599c8 to your computer and use it in GitHub Desktop.
Save thomashollier/78fcb8649fa6b8c1435607b968d599c8 to your computer and use it in GitHub Desktop.
pyenv cheat sheet
# Pyenv cheat sheet
"pyenv" allows you to install and manage different versions of python on the same machine
"pyenv virtualenv" allows you to have and manage different package install environments
brew install pyenv pyenv-virtualenv
https://realpython.com/intro-to-pyenv
### List installed python versions
pyenv versions
### Set and show active global version
pyenv global 3.10.11
pyenv global
### Set and show a locally active version
### This creates a .python-version file in the directory the command was run from
### The local version persists for subdirectories
pyenv local 3.11.3
pyenv local
### Show how pyenv is deciding on the version to use
pyenv versions
### You can explicitely override whatever version gets set with env variable
PYENV_VERSION=3.10.11
### Create a virtualenv
pyenv virtualenv 3.10.11 my_env
### Activate the virtual environment in the current working dir
### Creates a .python-version file with the environment name
### rather than the python version name
pyenv local my_env
pyenv local
### Show versions and environments, and current activated one
pyenv versions
### Explicitly set the environment or override the local one
pyenv activate my_env
### Deactivate it
pyenv deactivate
### Run script using environment rather than path
#!/usr/bin/env python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment