Bottom Page

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 pyenv Simple Python Version Management
Here gone look at setting up pyenv.
Will be using for Mint 19,work same for Ubuntu 18,for other look at wiki.
Both of these distros come with Python 3.6.5 as default Python 3 so pretty good updated.
Will be using pyenv to install Python 3.7.2 first,later look at eg Anaconda,PyPy...ect.
tom@tom-VirtualBox:~$ python -V
Python 2.7.15rc1

tom@tom-VirtualBox:~$ python3 -V
Python 3.6.5
Why pyenv?
  • pyenv will install Python or other Distribution(Anaconda,PyPy,MicroPython...ect),set it as system wide installation(or run it in a shell seesion).
  • No more using python3 or pip3 or sudo or --user when pip install something.
  • It's always python and pip to version set as global,and pip install requests to global version.
  • It's safe and will not mess with your OS,can go back to default pyenv local system or remove all rm -rf $(pyenv root)

Setting up pyenv
This is a one time setup.
  1. Install tool for building Python and distributions
  2. Use git to download pyenv
  3. Add 3 lines last in ~/.bashrc

1. Install building tools
sudo apt-get update
sudo apt-get install python3-dev
sudo apt install python3-pip
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev
# Scientific package headers(Numpy, Matplotlib, SciPy, etc.)
sudo apt-get install -y libpng-dev libfreetype6-dev
2. Download pyenv
git clone ~/.pyenv
3. Add to ~/.bashrc
Open in nano:
nano ~/.bashrc
Add these 3 lines last in ~/.bashrc:
# Load pyenv automatically
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
Ctrl-O <enter>(save) Ctrl-X(exit)
Restart shell.

pyenv test and usage
As see under no error loading using pyenv command.
tom@tom-VirtualBox:~$ pyenv version
3.7.2 (set by /home/tom/.pyenv/version)
tom@tom-VirtualBox:~$ python -V
Python 3.7.2
Now can look at pyenv install --list
A lot to choice from,let's go back in time and install Python 2.4 and set it Global(system wide installation).
tom@tom-VirtualBox:~$ pyenv install 2.4
Downloading Python-2.4.tgz...
Installing Python-2.4...
Installed setuptools-1.4.2 to /home/tom/.pyenv/versions/2.4
Installed pip-1.1 to /home/tom/.pyenv/versions/2.4

tom@tom-VirtualBox:~$ pyenv global 2.4
tom@tom-VirtualBox:~$ python -V
Python 2.4
tom@tom-VirtualBox:~$ pip -V
usage: pip COMMAND [OPTIONS]

pip: error: no such option: -V
As we see back to pip version 1.1(newest today is 18.1),it did not even have -V to show version.
But it's installed.
tom@tom-VirtualBox:~$ pip
usage: pip COMMAND [OPTIONS]

pip: error: You must give a command (use "pip help" to see a list of commands)
Let's go back to Python 3.7.2,flexibility is the strength of pyenv.
tom@tom-VirtualBox:~$ pyenv global 3.7.2
tom@tom-VirtualBox:~$ python -V
Python 3.7.2
tom@tom-VirtualBox:~$ pip -V
pip 18.1 from /home/tom/.pyenv/versions/3.7.2/lib/python3.7/site-packages/pip (python 3.7)
Larz60+ and micseydel like this post
Upgrade to Python 3.8.1 this should be easy if have pyenv up and working.
Here is demo on my Linux Mint 19.
# Update pyenv to get new versions list
tom@tom:~$ pyenv update

# Look at available versions 
tom@tom:~$ pyenv install --list

# Install
tom@tom:~$ pyenv install 3.8.1
Downloading Python-3.8.1.tar.xz...
Installing Python-3.8.1...
Installed Python-3.8.1 to /home/tom/.pyenv/versions/3.8.1

# Set as system wide version
tom@tom:~$ pyenv global 3.8.1

# Test
tom@tom:~$ python
Python 3.8.1 (default, Feb 11 2020, 09:18:58) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(walrus := True)
>>> exit()

tom@tom:~$ pip -V
pip 19.2.3 from /home/tom/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pip (python 3.8)
Larz60+ likes this post

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)