nordvpn

Manage multiple Python versions using pyenv

Manage multiple Python versions using pyenv

In this tutorial, I will show you how to Manage multiple Python versions using pyenv. You can install pyenv on mostly all the Linux distributions and Mac also.

pyenv lets you easily switch between multiple versions of Python. It’s simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build and modified for Python.

Install Python 3.8 alpha on Ubuntu 18.10

Requirements

Before install pyenv, there are some dependencies that we need to install because of pyenv build python from source.

On Ubuntu/Debian

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl

On RHEL/CentOs

sudo yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite \ sqlite-devel openssl-devel xz xz-devel libffi-devel

1. Install pyenv

Let’s start with installing pyenv. Installation of pyenv is pretty simple. Use the following command to install pyenv.

curl https://pyenv.run | bash

In this end, you will see a warning.

WARNING: seems you still have not added 'pyenv' to the load path.

# Load pyenv automatically by adding
# the following to ~/.bashrc:

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

So follow the instruction and add the following in ~/.bashrc and then execute the following command:

source ~/.bashrc

Now you will be able to use pyenv.

Install pyenv on Mac

On Mac, you can use brew to install pyenv.

brew install pyenv

2. Install Python using pyenv

Now we have installed pyenv let’s install python using pyenv. You can install any specific version of python.

$ pyenv install 3.7.0
Downloading Python-3.7.0.tar.xz...
-> https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
Installing Python-3.7.0...
Installed Python-3.7.0 to /root/.pyenv/versions/3.7.0

3. List installed python versions

You can list locally installed versions with pyenv.

$ pyenv versions
* system (set by /root/.pyenv/version)
3.7.0

How to install openjdk 10 Mac using brew (adoptopenjdk)

4. Set global python version

Now we will set the global python version using pyenv.

pyenv global 3.7.0

Now you can check the Python version

python -V
Python 3.7.0 (default)

So you can python 3.7.0 is now set globally. You can also check the global python version using the same command.
pyenv global
3.7.0

Or you can check installed versions. * means the current global python version.

pyenv versions
system
3.6.8
* 3.7.0 (set by /root/.pyenv/version)

If you like the tutorial please feel free to comment below.

Read Also: https://installvirtual.com/teamviewer-raspberry-pi-command-line/

1 Comment Posted

Leave a Reply

Your email address will not be published.


*



The reCAPTCHA verification period has expired. Please reload the page.

48-Hour Flash Sale! Courses from just $10.99