Python Forum
pyenv Simple Python Version Management
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyenv Simple Python Version Management
#1
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.
[email protected]:~$ python -V
Python 2.7.15rc1

[email protected]:~$ 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,eg 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 and install pyenv
  3. Add 4 lines last in ~/.bashrc

1. Install building tools
Look at wiki for eg Mac OS X and other distros.
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. This download and install pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtuale
git clone https://github.com/pyenv/pyenv-update.git $(pyenv root)/plugins/pyenv-update
3. Add to ~/.bashrc
Open in nano as shown under,or eg vim or text editor of choice.
nano ~/.bashrc
Add these 4 lines last in ~/.bashrc
# Load pyenv automatically when shell start
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Save:
Ctrl-O <enter>(save) Ctrl-X(exit)
Restart shell.

pyenv test and usage
As see under no error loading using pyenv command.
[email protected]:~$ pyenv version
3.7.2 (set by /home/tom/.pyenv/version)
[email protected]:~$ 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).
[email protected]:~$ pyenv install 2.4
Downloading Python-2.4.tgz...
-> https://www.python.org/ftp/python/2.4/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

[email protected]:~$ pyenv global 2.4
[email protected]:~$ python -V
Python 2.4
[email protected]:~$ 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.
[email protected]:~$ 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.
[email protected]:~$ pyenv global 3.7.2
[email protected]:~$ python -V
Python 3.7.2
[email protected]:~$ pip -V
pip 18.1 from /home/tom/.pyenv/versions/3.7.2/lib/python3.7/site-packages/pip (python 3.7)
Reply
#2
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
[email protected]:~$ pyenv update

# Look at available versions 
[email protected]:~$ pyenv install --list
.....
  3.7.5
  3.7.5rc1
  3.7.6
  3.8.0
  3.8-dev
  3.8.1
  3.9-dev

# Install
[email protected]:~$ pyenv install 3.8.1
Downloading Python-3.8.1.tar.xz...
-> https://www.python.org/ftp/python/3.8.1/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
[email protected]:~$ pyenv global 3.8.1

# Test
[email protected]:~$ 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)
True
>>> exit()

[email protected]:~$ pip -V
pip 19.2.3 from /home/tom/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pip (python 3.8)
likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020