[HowTo] Upgrading to new python version in a clean fashion
Posted: 01 Nov 2017, 12:05
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):
Requirement for "cryptography" package:
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:
Log out and login again, to reload the bash_profile
This only works when you're in your "myproject" directory:
Leave the directory and it won't work, as expected:
Python programs should start with the shebang
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
Code: Select all
# apt-get install libffi-dev
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 -)"
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
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
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
Code: Select all
#!/usr/bin/env python