How to install Python with pyenv version manager

I am using different programming languages like C#, Java, Node.js etc and need to manage runtime versions in my local. So, I like to use runtime version managers.

For example, there are some runtime version managers in Node.js community like nvm or n.

Let's say I work for one Node.js project in dev machine with Node v8.0.0 but other project needs Node v6.0.0

In order to handle, different versions in same machine, we may use runtime version managers.

I just want to find a way to switch between different Python runtime version so that found pyenv runtime version manager.

Pyenv is a simple, powerful and cross-platform tool for managing multiple versions of Python on a single machine. It is very useful when you need to switch between different Python versions for different projects, or when different applications on your system require different Python versions.

So, we can install, uninstall, list or switch between different versions.

Pyenv installation

Click pyenv link for more detailed installation.

Installing pyenv with Homebrew

First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit my post.

Run the following commands in your terminal. But, just copy commands without $ sign.

$ brew update
$ brew install pyenv

Setting PATH

Checking shell

output of echo $SHELL can be bash, zsh or fish

$ echo $SHELL

/usr/local/bin/bash

# OR

/bin/zsh

Run the following command for bash, zsh, etc configuration.

$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc

and restart your terminal manually or run the following command to restart automatically.

$ exec "$SHELL"

Upgrading pyenv

$ brew upgrade pyenv

Uninstall pyenv

$ rm -rf $(pyenv root)
$ brew uninstall pyenv

Pyenv commands

List all Python versions installed in system

$ pyenv versions

  system
  3.7.3
* 3.8.2 (set by /Users/kenanhancer/.pyenv/version)

Show current active Python version in system

$ pyenv version

3.8.2 (set by /Users/kenanhancer/.pyenv/version)
Continue reading