Linux usually comes with the default Python, but generally we will use a higher version of Python, so we need a version converter. These versions of Python do not affect each other.
1. Install pyenv
Execute the following command in the terminal to install pyenv and its plugins:
$ curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
2. After the installation is complete, add the following statement to ~/.bashrc and save:
1.export PYENV_ROOT="$HOME/.pyenv" 2.export PATH="$PYENV_ROOT/bin:$PATH" 3.eval "$(pyenv init -)"
Then restart the terminal.
3. Check the Python versions that can be installed according to the version manager pyenv. Enter the command in the terminal:
$ pyenv install --list
This command will list the Python versions that can be installed with pyenv.
4. Install the Python dependencies.
In the process of compiling Python, some other library files will be relied on. The pre-installed libraries are as follows, and enter in the terminal:
sudo apt-get update sudo apt-get install make build-essential libssl-dev zlib1g-dev sudo apt-get install libbz2-dev libreadline-dev libsqlite3-dev wget curl sudo apt-get install llvm libncurses5-dev libncursesw5-dev
5. Install the specified version of Python (3.5.3 is used here as an example).
$ pyenv install 3.5.3
6. Update the database.
$ pyenv rehash
7. Set the global python version.
$ pyenv global 3.5.3 $ pyenv versions
If it shows next:
system * 3.5.3 (set by /home/seisman/.pyenv/version)
That is, your newly downloaded Python version has been set as the default version.
8. Confirm and use the python version.
Confirm version:
$ python
Use:
Enter python to use the new version of python.