Skip to content

Latest commit

 

History

History
185 lines (125 loc) · 3.3 KB

pyenv.md

File metadata and controls

185 lines (125 loc) · 3.3 KB

pyenv

See first: pyenv docs

These instructions come from this intro to pyenv article, but this blog post also looks good.

Table of Contents

Install pyenv

Install dependencies:

brew install openssl readline sqlite3 xz zlib

Install pyenv:

curl https://pyenv.run | bash

Note: the most recent instruction in the pyenv docs say you can just do this:

brew update
brew install pyenv

There will be a message in the console saying that you need to update your PATH. Be sure to read because the instructions seem to change as they update pyenv.

Basically, I have to add to my .bash_profile:

export PATH="$HOME/.pyenv/shims:$PATH"

However, they have a longer, roundabout way of doing this:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

The reasons are explained in the pyenv docs.

Be sure to restart .bash_profile:

source ~/.bash_profile

Install python versions

List all versions (warning: there's a lot):

pyenv install --list

List specific versions:

pyenv install --list | grep " 3\.[678]"

Install a version:

pyenv install -v 3.7.8

Each version installed with pyenv is located in your pyenv root directory:

ls ~/.pyenv/versions/

Remove a version

Check the versions you have first:

ls ~/.pyenv/versions/

Then remove one like this:

rm -rf ~/.pyenv/versions/2.7.15

or like this:

pyenv uninstall 2.7.15

Using your versions

First check what you have:

pyenv versions
* system (set by /Users/jessicarush/.pyenv/version)
  3.5.9
  3.6.11
  3.7.8
  3.8.5

The asterisk indicates which version is currently running. In the above output it's the system os version (2.7.16).

To switch you can use the global command:

pyenv global 3.7.8

now check:

pyenv versions
system
3.5.9
3.6.11
* 3.7.8 (set by /Users/jessicarush/.pyenv/version)
3.8.5

A great way to get peace of mind that the version of Python you just installed is working properly is to run the built-in test suite:

python -m test

If you ever want to go back to the system version:

pyenv global system

Other commands

Note, you will need to update pyenv to see new python versions to install with pyenv install --list. To update pyenv:

pyenv update

Note that if you want to see which python, there will be a pyenv shim in place:

which python
/Users/jessicarush/.pyenv/shims/python

To see the actual path, you can run the following:

pyenv which python
/usr/bin/python

To see a complete list of pyenv commands:

pyenv commands

Each command has a --help flag that will give you more detailed information.

See also: pyenv commands reference