- Install build dependencies
sudo 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 libffi-dev liblzma-dev python-openssl
- Install pyenv
curl https://pyenv.run | bash
- Add following lines to
~/.bashrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="/home/pi/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
- If you are combining pyenv and pipenv, then set the environment variable PIPENV_PYTHON to $PYENV_ROOT/shims/python. This will make Pipenv use pyenv’s active Python version to create virtual environments by default.
- Add
PIPENV_PYTHON="$PYENV_ROOT/shims/python"
to~/.bashrc
. And reload your shellexec "$SHELL"
- Check available python versions
pyenv install --list | grep " 3\.[678]"
. To see allpyenv install --list
- Install the version you need, for instance
pyenv install -v 3.7.2
- To see where the python versions are installed enter
ls ~/.pyenv/versions/
- Remove, if you need, by entering
rm -rf ~/.pyenv/versions/3.7.2
orpyenv uninstall 3.7.2
- Check what versions of Python you have available,
pyenv versions
(* indicates the system Python version)
* system (set by /home/pi/.pyenv/version)
3.7.2
- To confirm use
which python
- To use version 3.7.2, then you can use the global command
pyenv global 3.7.2
- Check python version now
pyenv version
system
3.7.2 (set by /home/pi/.pyenv/version)
- To go back to the system version of Python enter
pyenv global system
and check version to confirm.
- Install build dependencies
brew install openssl readline sqlite3 xz zlib
- Install pyenv
curl https://pyenv.run | bash
- Add following lines to
~/.bashrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="/home/pi/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
- If you are combining pyenv and pipenv, then set the environment variable PIPENV_PYTHON to $PYENV_ROOT/shims/python. This will make Pipenv use pyenv’s active Python version to create virtual environments by default.
- Add
PIPENV_PYTHON="$PYENV_ROOT/shims/python"
to~/.bashrc
. And reload your shellexec "$SHELL"
- Check available python versions
pyenv install --list | grep " 3\.[678]"
. To see allpyenv install --list
- Install the version you need, for instance
pyenv install -v 3.7.2
- To see where the python versions are installed enter
ls ~/.pyenv/versions/
- Remove, if you need, by entering
rm -rf ~/.pyenv/versions/3.7.2
orpyenv uninstall 3.7.2
- Check what versions of Python you have available,
pyenv versions
(* indicates the system Python version)
* system (set by /home/pi/.pyenv/version)
3.7.2
- To confirm use
which python
- To use version 3.7.2, then you can use the global command
pyenv global 3.7.2
- Check python version now
pyenv version
system
3.7.2 (set by /home/pi/.pyenv/version)
- To go back to the system version of Python enter
pyenv global system
and check version to confirm.
Pro Tip To check the version of Python installed is working properly is to run the built-in test suite.
$ pyenv global 3.8-dev
$ python -m test
----->will verify your installation<---------
For further detail info go to Intro-to-pyenv