Skip to content

Installing Python

MGL1994 edited this page Jan 18, 2021 · 22 revisions

Although, at time of writing, Python 2.x is still to be found as the default python install on many systems, it is no longer maintained since January of 2020. Python 3.x has some distinct differences so unless you specifically want to test your code in 2.x, make sure you have access to Python 3.x. You can confirm your version with python --version.

There are multiple ways to manage your Python versions. This guide looks at just one of them.

Installing pyenv / pyenv-win

On MacOS and Linux, pyenv is a great option for installing multiple versions and being able to switch between them.

  • Install pyenv via homebrew: brew install pyenv
  • Add pyenv init to your shell:
    • echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.<your-shell-config-file>
    • Your shell config file may be .zshrc, .bash_profile, .bashrc
    • If you are not sure, cd ~, ls -lah and see which one is there!

On Windows, there is a pyenv-win port.

  • Install pyenv via Chocolatey: choco install pyenv-win
  • Close and reopen your terminal app and run pyenv --version
    • If you receive a command not found error, check the documentation for how to manually set environment variables
  • Navigate to your home directory and run pyenv rehash

Basic pyenv / pyenv-win usage

On MacOS and Linux

  • Install a Python version with pyenv: pyenv install <latest-version> (use pyenv install -l to see all the options, you will need to replace <latest-version> with the actual latest version eg. 3.9.1!)
  • See your installed Python version: pyenv versions
  • Switch to a version: pyenv global <version> eg. pyenv global 3.9.1
  • Close and reopen your terminal app.
  • Confirm success by running python --version

On Windows

Note: if you have previously installed Python on your machine this will likely override pyenv-win and so you should uninstall this before continuing.

  • Install a Python version with pyenv: pyenv install <latest-version> (use pyenv install -l to see all the options, you will need to replace <latest-version> with the actual latest version eg. 3.9.1!)
  • If you do not see all the versions of Python you are expecting you may need to run pyenv update.
  • See your installed Python version: pyenv versions
  • Switch to a version: pyenv global <version> eg. pyenv global 3.9.1
  • Run pyenv rehash to update pyenv with your new settings.
  • Confirm success by running python --version
Clone this wiki locally