[HowTo] Upgrading to new python version in a clean fashion

Post Reply
Wulf
Posts: 25
Joined: 01 Nov 2017, 11:49

[HowTo] Upgrading to new python version in a clean fashion

Post by Wulf »

I needed a more recent (>= 3.5) python3 version on my RevPi, but there was no Raspbian/Stretch image available yet.

Best way I found is to use https://github.com/pyenv/pyenv which downloads cpython sources and installs them, all with a normal user account. It also manages virtualenvs.
Here's a short walkthrough.

Requirements (from https://github.com/pyenv/pyenv/wiki/Com ... d-problems):

Code: Select all

# 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
Requirement for "cryptography" package:

Code: Select all

# apt-get install libffi-dev
And now without root, as nomal user; make sure to substitute your real username below, or copy+paste from what the installer asked you to do:

Code: Select all

$ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

$ cat >> ~/.bash_profile
export PATH="/home/<USERNAME>/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Log out and login again, to reload the bash_profile

Code: Select all

$ pyenv install 3.5.3
$ mkdir myproject
$ cd myproject
$ pyenv local 3.5.3
$ pyenv virtualenv myvenv
$ pyenv local 3.5.3/envs/myvenv
$ pip install wheel
$ pip install cryptography
This only works when you're in your "myproject" directory:

Code: Select all

$ python -c 'import sys; print(sys.version_info); import cryptography; print(cryptography.__version__)'
sys.version_info(major=3, minor=5, micro=3, releaselevel='final', serial=0)
2.1.2
Leave the directory and it won't work, as expected:

Code: Select all

$ cd ..
$ python -c 'import sys; print(sys.version_info); import cryptography; print(cryptography.__version__)'
sys.version_info(
major=2, minor=7, micro=9, releaselevel='final', serial=0)
Traceback (most recent call last):
  File "<string>", line 1,
in <module>
ImportError: No module named cryptography
Python programs should start with the shebang

Code: Select all

#!/usr/bin/env python
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41

Re: [HowTo] Upgrading to new python version in a clean fashion

Post by volker »

Thnx for supporting our community with this excellent description!
Unser RevPi Motto: Don't just claim it - make it!
Post Reply