程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Linux Debian installs or manages multiple Python versions

編輯:Python

stay Debian Install or manage multiple Python edition

​ 2021-05-13 19:04:55 +08 Number of words :4772 label : LinuxPython

Ubuntu 20.04 Of Python The default version is 3.8, Meet the requirements for normal use . and Ubuntu 18.04 On is 3.6 edition , Earlier 16.04 On the other hand, it's 3.5 edition . and Debian The stable version of buster, Only now 3.7,Deepin It's the same thing . In the past ,Python When it is published every two years ,Debian The rhythm is barely acceptable ; Now it is published once a year , It seems too backward . at present (2021 year 5 month ),Python The latest stable version is 3.9,3.10 Is still in the alpha Stage .

If for some reason , Other... Need to be used on each distribution Python edition , Additional installation is required . Actually ,deb Department , It's about Deepin. Ubuntu It is not backward ,Debian It can also be used. unstable or testing Source , only Deepin The food is unacceptable .

Environmental preparation ¶

sudo apt-get install -y \
build-essential \
curl \
git \
libbz2-dev \
libffi-dev \
liblzma-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
llvm \
python-openssl \
tk-dev \
wget \
xz-utils \
zlib1g-dev

Above is Ubuntu in , download 、 compile Python The environment required by the source code . The following schemes , All depend on these packages together .

Compile and install from source ¶

cd /tmp
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tar.xz
tar -xf Python-3.9.5.tar.xz
cd Python-3.9.5
./configure --enable-optimizations --prefix=$HOME/.python/3.9.5
make -j8
make install
cd $HOME/.python
ln -s 3.9.5 default

If you want to install globally for all users , The installation position can be selected in /opt/python/, then sudo make install. After installation , Add the installation location to PATH front , Overwrite system version :

# In ~/.bashrc
export PATH=$HOME/.python/default/bin:$PATH
# Or for global /etc/profile
export PATH=/opt/python/default/bin:$PATH

If you want to support multiple versions , The one above default Soft links can generate value . Install other versions in the same directory , Then replace the soft connection .

update-alternatives ¶

Is there any way to avoid configuration PATH, No need to manually operate the soft link , It can also automatically manage multiple Python Version of ?

Yes ,update-alternatives Welcome .

New candidate ¶

In source make After compilation ,sudo make install To /opt/python/3.9.5 Catalog . Then execute the following command :

# update-alternatives --install <link> <name> <path> <priority>
sudo update-alternatives --install /usr/local/bin/python3 python3 /opt/python/3.9.5/bin/python3 80

update-alternatives The principle is , At the designated <link> Location , Create soft link <link> -> /etc/alternatives/<name>. Then create soft links /etc/alternatives/<name> -> <path>. Because in PATH in ,/usr/local/bin The default row is /usr/bin front , So this new python3 Will be used first , Implement the replacement of the system version .

<priority> Refer to , When multiple versions exist at the same time , Which one is used by default . The greater the numerical , The higher the priority .

Update candidate ¶

Same command , Existing candidate priorities can be updated .

sudo update-alternatives --install /usr/local/bin/python3 python3 /opt/python/3.9.5/bin/python3 50

You can also add new candidates , For example, the original system /usr/bin/python3.

sudo update-alternatives --install /usr/local/bin/python3 python3 /usr/bin/python3 100

Query candidates ¶

adopt --query <name>, You can query the status of a candidate .

$ update-alternatives --query python3
Name: python3
Link: /usr/local/bin/python3
Status: auto
Best: /usr/bin/python3
Value: /usr/bin/python3
Alternative: /opt/python/3.9.5/bin/python3
Priority: 50
Alternative: /usr/bin/python3
Priority: 100

These are the two settings just now python3 The candidate version of . If --install More versions , It can also be found here .

If you want to query python3 All candidates except , Can run update-alternatives --all, but Not recommended . This is a lot of information , And there are some situations that need to be handled with the same priority . therefore , You might as well go ls /etc/alternatives.

Adjust the candidate version ¶

In automatic mode ,/usr/alternatives/python3 Will link to the version with the highest priority . If manual adjustment is required , Need to use --set <name> <path>.

$ sudo update-alternatives --set python3 /opt/python/3.9.5/bin/python3
update-alternatives: using /opt/python/3.9.5/bin/python3 to provide /usr/local/bin/python3 (python3) in manual mode
$ update-alternatives --query python3
Name: python3
Link: /usr/local/bin/python3
Status: manual
Best: /usr/bin/python3
Value: /opt/python/3.9.5/bin/python3
Alternative: /opt/python/3.9.5/bin/python3
Priority: 50
Alternative: /usr/bin/python3
Priority: 100
$ /usr/local/bin/python3 --version
Python 3.9.5

--set after , Reuse --query see , You can find Status Turned into manual, Manual mode . use --set It can be done to python3 The version of . If you want to change back , It can be used --auto <name>.

$ sudo update-alternatives --auto python3
update-alternatives: using /usr/bin/python3 to provide /usr/local/bin/python3 (python3) in auto mode

Delete ¶

If you need to delete a version , have access to --remove <name> <path>

sudo update-alternatives --remove python3 /opt/python/3.9.5/bin/python3

If you need to delete a candidate , have access to --remove-all <name>

sudo update-alternatives --remove-all python3

pyenv ¶

In addition to managing multiple Python Out of version , How to discover 、 download 、 compile , It's also a problem . pyenv Is the most popular solution in this area .

Although I've heard of you for a long time , However, the orphan is still extremely resistant to this plan , So it was only recently studied . It should be noted that , It's just a development environment solution , Not suitable for production environment .

install pyenv ¶

curl https://pyenv.run | bash

If the network is normal , The above installation is convenient and painless . However , A very important step , Is to go GitHub On clone It's a few code bases down . therefore , It may be necessary to refer to 《 utilize github.com.cnpmjs.org Quick download GitHub Warehouse 》.

To configure pyenv ¶

After installation , You also need to include the following , Add to ~/.bashrc in .

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
export PYENV_SHELL="bash"
source "$PYENV_ROOT/completions/pyenv.bash"

Another option is to use eval, If you don't care what it does . and , The above configuration removes the pair of pyenv-virtualenv Support for . therefore , If you need a complete fool configuration , Then you can use the following .

eval "$(pyenv init -)"
eval "$(pyenv virtulenv-init -)"

pyenv The executable of , stay $PYENV_ROOT/bin Next . And the default that it manages Python Related executable files , Include pythonpydocpip etc. , Soft link to $PYENV_ROOT/shims Next . In addition to installation , In version management , It and update-alternatives Using similar ideas and techniques .

pyenv Install a new version ¶

List optional installations Python edition :

$ pyenv install --list
Available versions:
2.1.3
2.2.3
2.3.7
2.4.0
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.5.0
2.5.1
2.5.2
2.5.3
2.5.4
2.5.5
2.5.6
2.6.6
2.6.7
2.6.8
2.6.9
2.7.0
2.7-dev
2.7.1
2.7.2
2.7.3
2.7.4
2.7.5
2.7.6
2.7.7
2.7.8
2.7.9
2.7.10
2.7.11
2.7.12
2.7.13
2.7.14
2.7.15
2.7.16
2.7.17
2.7.18
3.0.1
3.1.0
3.1.1
3.1.2
3.1.3
3.1.4
3.1.5
3.2.0
3.2.1
3.2.2
3.2.3
3.2.4
3.2.5
3.2.6
3.3.0
3.3.1
3.3.2
3.3.3
3.3.4
3.3.5
3.3.6
3.3.7
3.4.0
3.4-dev
3.4.1
3.4.2
3.4.3
3.4.4
3.4.5
3.4.6
3.4.7
3.4.8
3.4.9
3.4.10
3.5.0
3.5-dev
3.5.1
3.5.2
3.5.3
3.5.4
3.5.5
3.5.6
3.5.7
3.5.8
3.5.9
3.5.10
3.6.0
3.6-dev
3.6.1
3.6.2
3.6.3
3.6.4
3.6.5
3.6.6
3.6.7
3.6.8
3.6.9
3.6.10
3.6.11
3.6.12
3.6.13
3.7.0
3.7-dev
3.7.1
3.7.2
3.7.3
3.7.4
3.7.5
3.7.6
3.7.7
3.7.8
3.7.9
3.7.10
3.8.0
3.8-dev
3.8.1
3.8.2
3.8.3
3.8.4
3.8.5
3.8.6
3.8.7
3.8.8
3.8.9
3.8.10
3.9.0
3.9-dev
3.9.1
3.9.2
3.9.3
3.9.4
3.9.5
3.10.0b1
3.10-dev
3.11-dev
activepython-2.7.14
activepython-3.5.4
activepython-3.6.0
anaconda-1.4.0
anaconda-1.5.0
anaconda-1.5.1
anaconda-1.6.0
anaconda-1.6.1
anaconda-1.7.0
anaconda-1.8.0
anaconda-1.9.0
anaconda-1.9.1
anaconda-1.9.2
anaconda-2.0.0
anaconda-2.0.1
anaconda-2.1.0
anaconda-2.2.0
anaconda-2.3.0
anaconda-2.4.0
anaconda-4.0.0
anaconda2-2.4.0
anaconda2-2.4.1
anaconda2-2.5.0
anaconda2-4.0.0
anaconda2-4.1.0
anaconda2-4.1.1
anaconda2-4.2.0
anaconda2-4.3.0
anaconda2-4.3.1
anaconda2-4.4.0
anaconda2-5.0.0
anaconda2-5.0.1
anaconda2-5.1.0
anaconda2-5.2.0
anaconda2-5.3.0
anaconda2-5.3.1
anaconda2-2018.12
anaconda2-2019.03
anaconda2-2019.07
anaconda3-2.0.0
anaconda3-2.0.1
anaconda3-2.1.0
anaconda3-2.2.0
anaconda3-2.3.0
anaconda3-2.4.0
anaconda3-2.4.1
anaconda3-2.5.0
anaconda3-4.0.0
anaconda3-4.1.0
anaconda3-4.1.1
anaconda3-4.2.0
anaconda3-4.3.0
anaconda3-4.3.1
anaconda3-4.4.0
anaconda3-5.0.0
anaconda3-5.0.1
anaconda3-5.1.0
anaconda3-5.2.0
anaconda3-5.3.0
anaconda3-5.3.1
anaconda3-2018.12
anaconda3-2019.03
anaconda3-2019.07
anaconda3-2019.10
anaconda3-2020.02
anaconda3-2020.07
anaconda3-2020.11
graalpython-20.1.0
graalpython-20.2.0
graalpython-20.3.0
graalpython-21.0.0
graalpython-21.1.0
ironpython-dev
ironpython-2.7.4
ironpython-2.7.5
ironpython-2.7.6.3
ironpython-2.7.7
jython-dev
jython-2.5.0
jython-2.5-dev
jython-2.5.1
jython-2.5.2
jython-2.5.3
jython-2.5.4-rc1
jython-2.7.0
jython-2.7.1
jython-2.7.2
micropython-dev
micropython-1.9.3
micropython-1.9.4
micropython-1.10
micropython-1.11
micropython-1.12
micropython-1.13
micropython-1.14
miniconda-latest
miniconda-2.2.2
miniconda-3.0.0
miniconda-3.0.4
miniconda-3.0.5
miniconda-3.3.0
miniconda-3.4.2
miniconda-3.7.0
miniconda-3.8.3
miniconda-3.9.1
miniconda-3.10.1
miniconda-3.16.0
miniconda-3.18.3
miniconda2-latest
miniconda2-3.18.3
miniconda2-3.19.0
miniconda2-4.0.5
miniconda2-4.1.11
miniconda2-4.3.14
miniconda2-4.3.21
miniconda2-4.3.27
miniconda2-4.3.30
miniconda2-4.3.31
miniconda2-4.4.10
miniconda2-4.5.1
miniconda2-4.5.4
miniconda2-4.5.11
miniconda2-4.5.12
miniconda2-4.6.14
miniconda2-4.7.10
miniconda2-4.7.12
miniconda3-latest
miniconda3-2.2.2
miniconda3-3.0.0
miniconda3-3.0.4
miniconda3-3.0.5
miniconda3-3.3.0
miniconda3-3.4.2
miniconda3-3.7.0
miniconda3-3.7-4.8.2
miniconda3-3.7-4.8.3
miniconda3-3.7-4.9.2
miniconda3-3.8.3
miniconda3-3.8-4.8.2
miniconda3-3.8-4.8.3
miniconda3-3.8-4.9.2
miniconda3-3.9.1
miniconda3-3.9-4.9.2
miniconda3-3.10.1
miniconda3-3.16.0
miniconda3-3.18.3
miniconda3-3.19.0
miniconda3-4.0.5
miniconda3-4.1.11
miniconda3-4.2.12
miniconda3-4.3.11
miniconda3-4.3.14
miniconda3-4.3.21
miniconda3-4.3.27
miniconda3-4.3.30
miniconda3-4.3.31
miniconda3-4.4.10
miniconda3-4.5.1
miniconda3-4.5.4
miniconda3-4.5.11
miniconda3-4.5.12
miniconda3-4.6.14
miniconda3-4.7.10
miniconda3-4.7.12
miniforge3-4.9.2
miniforge3-4.10
pypy-c-jit-latest
pypy-dev
pypy-stm-2.3
pypy-stm-2.5.1
pypy-1.5-src
pypy-1.6
pypy-1.7
pypy-1.8
pypy-1.9
pypy-2.0-src
pypy-2.0
pypy-2.0.1-src
pypy-2.0.1
pypy-2.0.2-src
pypy-2.0.2
pypy-2.1-src
pypy-2.1
pypy-2.2-src
pypy-2.2
pypy-2.2.1-src
pypy-2.2.1
pypy-2.3-src
pypy-2.3
pypy-2.3.1-src
pypy-2.3.1
pypy-2.4.0-src
pypy-2.4.0
pypy-2.5.0-src
pypy-2.5.0
pypy-2.5.1-src
pypy-2.5.1
pypy-2.6.0-src
pypy-2.6.0
pypy-2.6.1-src
pypy-2.6.1
pypy-4.0.0-src
pypy-4.0.0
pypy-4.0.1-src
pypy-4.0.1
pypy-5.0.0-src
pypy-5.0.0
pypy-5.0.1-src
pypy-5.0.1
pypy-5.1-src
pypy-5.1
pypy-5.1.1-src
pypy-5.1.1
pypy-5.3-src
pypy-5.3
pypy-5.3.1-src
pypy-5.3.1
pypy-5.4-src
pypy-5.4
pypy-5.4.1-src
pypy-5.4.1
pypy-5.6.0-src
pypy-5.6.0
pypy-5.7.0-src
pypy-5.7.0
pypy-5.7.1-src
pypy-5.7.1
pypy2-5.3-src
pypy2-5.3
pypy2-5.3.1-src
pypy2-5.3.1
pypy2-5.4-src
pypy2-5.4
pypy2-5.4.1-src
pypy2-5.4.1
pypy2-5.6.0-src
pypy2-5.6.0
pypy2-5.7.0-src
pypy2-5.7.0
pypy2-5.7.1-src
pypy2-5.7.1
pypy2.7-5.8.0-src
pypy2.7-5.8.0
pypy2.7-5.9.0-src
pypy2.7-5.9.0
pypy2.7-5.10.0-src
pypy2.7-5.10.0
pypy2.7-6.0.0-src
pypy2.7-6.0.0
pypy2.7-7.0.0-src
pypy2.7-7.0.0
pypy2.7-7.1.0-src
pypy2.7-7.1.0
pypy2.7-7.1.1-src
pypy2.7-7.1.1
pypy2.7-7.2.0-src
pypy2.7-7.2.0
pypy2.7-7.3.0-src
pypy2.7-7.3.0
pypy2.7-7.3.1-src
pypy2.7-7.3.1
pypy3-2.3.1-src
pypy3-2.3.1
pypy3-2.4.0-src
pypy3-2.4.0
pypy3.3-5.2-alpha1-src
pypy3.3-5.2-alpha1
pypy3.3-5.5-alpha-src
pypy3.3-5.5-alpha
pypy3.5-c-jit-latest
pypy3.5-5.7-beta-src
pypy3.5-5.7-beta
pypy3.5-5.7.1-beta-src
pypy3.5-5.7.1-beta
pypy3.5-5.8.0-src
pypy3.5-5.8.0
pypy3.5-5.9.0-src
pypy3.5-5.9.0
pypy3.5-5.10.0-src
pypy3.5-5.10.0
pypy3.5-5.10.1-src
pypy3.5-5.10.1
pypy3.5-6.0.0-src
pypy3.5-6.0.0
pypy3.5-7.0.0-src
pypy3.5-7.0.0
pypy3.6-7.0.0-src
pypy3.6-7.0.0
pypy3.6-7.1.0-src
pypy3.6-7.1.0
pypy3.6-7.1.1-src
pypy3.6-7.1.1
pypy3.6-7.2.0-src
pypy3.6-7.2.0
pypy3.6-7.3.0-src
pypy3.6-7.3.0
pypy3.6-7.3.1-src
pypy3.6-7.3.1
pypy3.6-7.3.2-src
pypy3.6-7.3.2
pypy3.6-7.3.3-src
pypy3.6-7.3.3
pypy3.7-c-jit-latest
pypy3.7-7.3.2-src
pypy3.7-7.3.2
pypy3.7-7.3.3-src
pypy3.7-7.3.3
pypy3.7-7.3.4
pyston-2.2
stackless-dev
stackless-2.7-dev
stackless-2.7.2
stackless-2.7.3
stackless-2.7.4
stackless-2.7.5
stackless-2.7.6
stackless-2.7.7
stackless-2.7.8
stackless-2.7.9
stackless-2.7.10
stackless-2.7.11
stackless-2.7.12
stackless-2.7.14
stackless-3.2.2
stackless-3.2.5
stackless-3.3.5
stackless-3.3.7
stackless-3.4-dev
stackless-3.4.2
stackless-3.4.7
stackless-3.5.4
stackless-3.7.5

The above is at the top 、 There is no prefix , It's the official version . Except for the official CPython Out of version , It also supports anaconda、pypy、jython Others, such as Python Realization . This is also its biggest advantage .

Install a specific version , Just copy the values listed above . such as 3.9.5

$ pyenv install 3.9.5
Downloading Python-3.9.5.tar.xz...
-> https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tar.xz
Installing Python-3.9.5...
Installed Python-3.9.5 to /home/yanqd0/.pyenv/versions/3.9.5

pyenv Choose the version ¶

In terms of operation ,pyenv Designed a complex pyramid structure , Including four layers :

  • shell, Open a new shell, Inside is the specified version Python Environmental Science .
  • local, Create a... In the current directory .python-version Environmental Science . Within the current directory and its subdirectories ,Python The environment will automatically use the specified version .
  • global, At the user level ~/.pyenv/version Maintain a global version in . In scenarios other than the first two cases , Use the system default version .
  • system, If even ~/.pyenv/version No files , For example, in another user , The system version is used .

This actually complicates the problem , As if with these , You don't have to use a virtual environment . pyenv shell The design of the , and pipenv shell similar , Therefore, it is also replaced by the latter . pyenv local It is a trouble - seeking function , Not recommended . otherwise , In different directories Python Different versions , It's always you who get hurt . commonly , One Python The development environment of the project will use an independent virtual environment .

therefore , Only pyenv global It's worth it . It integrates reading and writing , Usage is as follows :

$ pyenv global
system
$ pyenv global 3.9.5
$ pyenv global
3.9.5

If you want to query the currently available Python What is the version , It can be used pyenv version or pyenv versions.

$ pyenv versions
system
3.8.10
* 3.9.5 (set by /home/yanqd0/.pyenv/version)
pypy3.7-7.3.4
pyston-2.2
$ pyenv version
3.9.5 (set by /home/yanqd0/.pyenv/version)

among , belt * Is the current version , The default is system, That is, the original version of the system . If it doesn't work pyenv local invite trouble , over there pyenv version and pyenv global The results should be consistent .

pyenv Other subcommands of ¶

adopt pyenv --help, Other functions can be viewed . But except for a few low-frequency query subcommands , Not recommended Use pyenv Other subcommands of .

$ pyenv root
/home/yanqd0/.pyenv
$ pyenv which python
/home/yanqd0/.pyenv/versions/3.9.5/bin/python
$ pyenv prefix
/home/yanqd0/.pyenv/versions/3.9.5

obviously , These query commands are somewhat useful . But if you know the trick of soft links , It doesn't work .

Include shellactivatevirtualenv Wait for orders , Are related to the virtual environment . This scheme , Can't solve all the problems , So let other more professional virtual environment solutions solve it . This aspect , You can refer to the 《Python Virtual environment in and how it works 》. Give Way pyenv Concentrate on many versions of Python that will do .

pyenv Of shims ¶

Even though pyenv Of shims, Looks like update-alternatives Of /etc/alternatives The catalog is similar , But it's more complicated . ~/.pyenv/shims Every file in , The content is the same , such as ~/.pyenv/shims/python3

#!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x
program="${0##*/}"
export PYENV_ROOT="/home/yanqd0/.pyenv"
exec "/home/yanqd0/.pyenv/libexec/pyenv" exec "$program" "[email protected]"

obviously , It is not a soft link , Instead, it hijacks the user's command line calls , I made a change with myself . Therefore , It can dynamically judge whether to use at run time shell、local、global、system Which version in .

pyenv-install+update-alternatives ¶

pyenv The default is a user level solution . in other words , Yes root And other users are invalid . But with a little adjustment , It can also be a system level solution .

If not used pyenv Virtual environment function of , And don't use complex shell、local、global Multi level version management , Then you can give up shims technology , Only pyenv install function .

use update-alternatives To install pyenv ¶

Install on the front /opt/pyenv On the basis of , Use update-alternatives You can do this without modifying the system PATH Under the circumstances , Use pyenv Multiple installed Python edition .

curl https://pyenv.run | sudo PYENV_ROOT="/opt/pyenv" bash
sudo update-alternatives --install /usr/local/bin/pyenv pyenv /opt/pyenv/bin/pyenv 100

Configuration of environment variables , It should also become a global operation . Write the following into /etc/profile.d/pyenv.sh in :

export PYENV_ROOT="/opt/pyenv"
export PYENV_SHELL="bash"
source "$PYENV_ROOT/completions/pyenv.bash"

Besides , In order to make sudo Can support it , Need make sudo These environment variables exist in . Write the following to /etc/sudoers.d/pyenv

Defaults env_keep += "PYENV_ROOT PYENV_SHELL"

such ,pyenv It is also available to other users . This can also avoid root User Python Different versions lead to sudo There are some strange problems . however , When performing write operations such as installation , Need to use sudo.

pyenv install --list
sudo pyenv install 3.8.10

and , Follow the configuration in this article , Its plug-in functions such as virtual environment are invalid .

use update-alternatives To manage Python edition ¶

Using sudo pyenv install After installing the desired version , You can add it as a candidate with the following command . such , From many different sources Python The version can be managed uniformly .

Of course ,update-alternatives comparison pyenv Of shims technology , There are still many shortcomings . such as , If you want unified management pydoc Wait for the order , Need to use --slave, This is a little troublesome .

sudo update-alternatives \
--install /usr/local/bin/python3 python3 /usr/bin/python3 100 \
--slave /usr/local/bin/pydoc3 pydoc3 /usr/bin/pydoc3
sudo update-alternatives \
--install /usr/local/bin/python3 python3 /opt/pyenv/versions/3.8.10/bin/python3 200 \
--slave /usr/local/bin/pydoc3 pydoc3 /opt/pyenv/versions/3.8.10/bin/pydoc3
sudo update-alternatives \
--install /usr/local/bin/python3 python3 /opt/pyenv/versions/3.9.5/bin/python3 300 \
--slave /usr/local/bin/pydoc3 pydoc3 /opt/pyenv/versions/3.9.5/bin/pydoc3

stay Python Multi version environment ,pip Usually by python -m pip To run the , It would be more accurate .

summary ¶

Install from source 、 Manual management , To update-alternatives, Until then pyenv, Return to pyenv-install+update-alternatives. This article is regarded as Linux Next ,Python The main operations of multi version management have been finished . Besides , Also a little bit about the principle .


–install /usr/local/bin/python3 python3 /usr/bin/python3 100
–slave /usr/local/bin/pydoc3 pydoc3 /usr/bin/pydoc3
sudo update-alternatives
–install /usr/local/bin/python3 python3 /opt/pyenv/versions/3.8.10/bin/python3 200
–slave /usr/local/bin/pydoc3 pydoc3 /opt/pyenv/versions/3.8.10/bin/pydoc3
sudo update-alternatives
–install /usr/local/bin/python3 python3 /opt/pyenv/versions/3.9.5/bin/python3 300
–slave /usr/local/bin/pydoc3 pydoc3 /opt/pyenv/versions/3.9.5/bin/pydoc3


stay Python Multi version environment ,`pip` Usually by `python -m pip` To run the , It would be more accurate .
## summary [¶](https://note.qidong.name/2021/05/multiple-python/# summary )
Install from source 、 Manual management , To `update-alternatives`, Until then [pyenv](https://github.com/pyenv/pyenv), Return to pyenv-install+update-alternatives. This article is regarded as Linux Next ,Python The main operations of multi version management have been finished . Besides , Also a little bit about the principle .

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved