Record of Installing Artifact Pyenv under Deepin

  • 2021-08-21 22:09:38
  • OfStack

Preface

In the past, the switch of python version was realized by modifying the soft connection under the/bin/directory. It was inconvenient for 10 points, and it was tedious to install the new python version. I tried an pyenv, and it felt really fragrant in an instant. Record the memo of the installation process.

Installation

Installing Dependent Libraries

This 1 step is required, otherwise python compilation will report warnings or exceptions, which will make some extensions unusable, such as:


WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Installation command:


# sudo apt install libssl-dev zlib1g-dev libbz2-dev \
     libreadline-dev libsqlite3-dev libffi-dev \
     libncurses5-dev libncursesw5-dev liblzma-dev

Installing pyenv

Download


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

Add the following to ~/. bashrc


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

Update environment variables


# source ~/.bashrc

Installing python


# pyenv install 3.8.5
Downloading Python-3.8.5.tar.xz...
-> https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz

pyenv downloads may be slow, so copy the download link shown, download it in your browser, place it in the ~/. pyenv/cache/directory (cache directory needs to be created manually), and then re-execute pyenv install 3.8. 5

Switching python Environment

Query the currently installed version of python


# pyenv versions
* system (set by /home/zpzhou/.pyenv/version)
 3.8.5

Switch version

You can use commands pyenv global <version> To switch.

Before switching:


# python -V
Python 2.7.13

Switch:


# pyenv global 3.8.5

After switching:


# python -V
Python 3.8.5

Summarize


Related articles: