Follow this article to install pyenv and easily switch to any python version on the Raspberry Pi system.
Switch Multiple Python Versions on Raspberry Pi Using pyenv
You can install pyenv on Raspberry Pi through the following steps:
Step 1: First, run the pyenv installation script on the Raspberry Pi system through the following command:
Step 2: Open the environment variable source file using the following command:
Then add the following lines in the file.
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Step 3: Save the file using “CTRL+X”.
Step 4: Apply the following command to reload your changes to the environment variable file.
Step 5: Now confirms the pyenv installation through the following command:
Step 6: To check for different Python versions, you can run the following pyenv command:
At the top of the list, you will see different Python versions and you can pick any version you want to install on the Raspberry Pi system.
I am installing Python version 3.8.0 and the command to install this version on the Raspberry Pi system is given below:
Note: Ignore the warning or any kind of issue because the above command will successfully install the selected Python version on the Raspberry Pi system.
Step 7: After completing the installation, run the following command to make the selected Python version global for all the users:
Step 8: Now, confirm the Python version through the below-given command:
The above command ensures that the Python version is successfully switched.
Conclusion
The pyenv is a helpful tool that allows users to switch to any python version within a few seconds. You can install this tool through an installation script. After that, you must add some lines inside the environment variable file and load the changes to install pyenv successfully. Later, you can install any python version using the “pyenv install” command and make the version global to use it on the Raspberry Pi system.