Update Python for Raspberry Pi to 3.7 or later with pyenv

What is pyenv?

A Python version control tool.

There are many articles on how to use pyenv, ** ・ In 3.7 or later, an error occurs during installation ** ** ・ The settings are not reflected at startup only with .bash_profile ** Therefore, I posted this article as a memorandum.

Things necessary

・ RaspberryPi connected to the network (RaspberryPi3 ModelB is used this time)

Method

I referred to here.

① Install pyenv

Install pyenv to update the Python version. I referred to here. (If you have already installed it, please skip it)

-Installation of required packages

sudo apt install git openssl libssl-dev libbz2-dev libreadline-dev libsqlite3-dev

・ In 3.7 or later, an error will occur if the following packages are not installed.

sudo apt install libffi-dev

-Copy pyenv from Github

git clone https://github.com/yyuu/pyenv.git ~/.pyenv

-Edit home / [username] /.bash_profile (create if not)

.bash_profile


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

・ After restarting Raspberry Pi, check the version of pyenv

pyenv --version

Success if the version is displayed like "pyenv 1.2.18-8-g5e8719ab"

** * When the version is not displayed ** Add the following contents to home / [user name] /. profile (Same content as in .bash_profile)

.profile


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

Reboot and run "pyenv --version" and you should see the version

② Update Python version

-Display a list of installable versions

pyenv install --list

-Install the desired version For example, if you want to install 3.7.6,

pyenv install 3.7.6

・ Version change

pyenv global 3.7.6

・ Check if the version has been updated

python --version
python3 --version

Both are successful if they are the updated version (3.7.6)

Recommended Posts

Update Python for Raspberry Pi to 3.7 or later with pyenv
Connect to MySQL with Python on Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
Unable to install Python with pyenv
Translate I2C device driver for Arduino to Python for Raspberry pi
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
[Raspberry Pi] Changed Python default to Python3
Memo to ask for KPI with python
Try fishing for smelt with Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Use python on Raspberry Pi 3 to light the LED with switch control!
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
Discord bot with python raspberry pi zero with [Notes]
Media programming with Raspberry Pi (preparation for audio)
Building an Anaconda environment for Python with pyenv
How to use Raspberry Pi pie camera Python
I tried L-Chika with Raspberry Pi 4 (Python edition)
I wanted to install Python 3.4.3 with Homebrew + pyenv
Get CPU information of Raspberry Pi with Python
How to use tkinter with python in pyenv
Little-known Python language specification (compatible with Python 3.4 or later)
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
Measure CPU temperature of Raspberry Pi with Python
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
I tried to create a button for Slack with Raspberry Pi + Tact Switch
Try to use up the Raspberry Pi 2's 4-core CPU with Parallel Python
GPGPU with Raspberry Pi
Install python with pyenv
DigitalSignage with Raspberry Pi
From setting up Raspberry Pi to installing Python environment
Easy IoT to start with Raspberry Pi and MESH
Try to visualize the room with Raspberry Pi, part 1
How to use the Raspberry Pi relay module Python
Try debugging Python on Raspberry Pi with Visual Studio.
Use Python installed with pyenv for PL / Python execution environment
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
For those who want to write Python with vim
Install pyenv on Raspberry Pi and version control Python
Output to "7-segment LED" using python on Raspberry Pi 3!
Display USB camera video with Python OpenCV with Raspberry Pi
Let's operate GPIO of Raspberry Pi with Python CGI
Raspberry Pi with Elixir, which is cooler than Python
Introduced python3-OpenCV3 to Raspberry Pi
Connect to BigQuery with Python
Mutter plants with Raspberry Pi
Run AWS IoT Device SDK for Python on Raspberry Pi
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
Python 3.4 or later standard pip
Try to display various information useful for debugging with python
Python beginner opens and closes interlocking camera with Raspberry Pi
Connect to Wikipedia with Python
How to update Python Tkinter to 8.6
Post to slack with Python 3
I tried running Movidius NCS with python of Raspberry Pi3
Create an LCD (16x2) game with Raspberry Pi and Python
Experiment to make a self-catering PDF for Kindle with Python
I talked to Raspberry Pi
Access google spreadsheet using python on raspberry pi (for myself)
Introducing PyMySQL to raspberry pi3
How to update with SQLAlchemy?
Run BNO055 python sample code with I2C (Raspberry Pi 3B)