Skip to content

Instantly share code, notes, and snippets.

@jsugarman
Created September 20, 2021 11:07
Show Gist options
  • Save jsugarman/6e3d418b1b1ac885e46f278548c046be to your computer and use it in GitHub Desktop.
Save jsugarman/6e3d418b1b1ac885e46f278548c046be to your computer and use it in GitHub Desktop.
python version maagement with pyenv

Python version management with pyenv

Information

  pyenv help
  pyenv version
  pyenv versions
  pyenv version-origin

Switching versions

There are several ways to switch. These are list in order of descending precedence:

  • For a shell amend PYENV_VERSION using pyenv shell

    pyenv shell 3.8.10
  • For an app, add a .python-version to the root and put the version or virtual env name or python version number that you are wanting to use.

  • For global settings use the root .python-version file

    vim $(pyenv root)/version
    
    • add list of version numbers
    • put the version you want at the top
    • note: you can have multiple active but only the top one will take effect
    # example .python-version file
    3.9.7
    3.8.10
    3.7.7
    3.6.5
    2.7.15
    

Installing new python versions

  • use pyenv install <version-number>
pyenv install 3.9.7
  • switch to that version using one of the methods above
pyenv shell 3.9.7

Virtualenv management with pyenv-virtualenv and pyenv

see pyenv-virtualenv for more

Information

pyenv virtualenvs

Create a new virtualenv

# create a named virtualenv for current python version
pyenv virtualenv my-virtual-env
# create a named virtualenv for specific python version
pyenv virtualenv 3.9.7 my-virtual-env-3.9.7

Activate/deactivate a virtualenv

pyenv activate my-virtual-env-3.9.7
pyenv deactivate

Delete virtualenv

pyenv uninstall my-virtual-env
# or
pyenv virtualenv-delete my-virtual-en
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment