还是写一下怎么在Ubuntu上安装高版本python吧,其实在CentOS上安装基本类似。
首先我们知道在ubunt上现在可以通过apt install python3.7,安装的是3.7.3版本,不支持apt安装3.8版本。
装完之后可以看到python版本是3.7.3
root@ubuntu-1804-102:~/Python-3.8.0b4# python3.7
Python 3.7.3 (default, Apr 3 2019, 19:16:38)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
当然我们可以安装3.7.4,也可以安装新版3.8.0b4, 发布日期是Aug. 29, 2019。
从官网下载到本机
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0b4.tgz
先解压
tar xzvf Python-3.8.0b4.tgz
进入解压目录
cd Python-3.8.0b4/
./configure
make
make install
编译过程中可能会有提示需要C套件,需要安装开发套件:
apt install build-essential
make install 过程中还碰到错误提示:
zipimport.ZipImportError: can't decompress data; zlib not available
还需要安装zlib
apt install zlib1g-dev
#装完后看下版本
root@ubuntu-1804-102:~/Python-3.8.0b4# gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
现在看机器上的python版本,是不是很多?
root@ubuntu-1804-102:~/Python-3.8.0b4# python3.7
Python 3.7.3 (default, Apr 3 2019, 19:16:38)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
root@ubuntu-1804-102:~/Python-3.8.0b4# python3.6
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
root@ubuntu-1804-102:~/Python-3.8.0b4# python
Python 2.7.15+ (default, Jul 9 2019, 16:51:35)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
root@ubuntu-1804-102:~/Python-3.8.0b4# python3
Python 3.8.0b4 (default, Sep 20 2019, 10:59:12)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
发现了没有,python 默认的还是python 2.7.15, python3 默认指向3.8。 现在我想把python指向3.7,那么先看一下软链接:
root@ubuntu-1804-102:~/Python-3.8.0b4# ls -l /usr/bin | grep python
-rwxr-xr-x 1 root root 1056 Apr 16 2018 dh_python2
lrwxrwxrwx 1 root root 23 Jul 9 16:51 pdb2.7 -> ../lib/python2.7/pdb.py
lrwxrwxrwx 1 root root 23 Aug 20 17:12 pdb3.6 -> ../lib/python3.6/pdb.py
lrwxrwxrwx 1 root root 23 Apr 3 19:16 pdb3.7 -> ../lib/python3.7/pdb.py
lrwxrwxrwx 1 root root 31 Oct 25 2018 py3versions -> ../share/python3/py3versions.py
lrwxrwxrwx 1 root root 9 Apr 16 2018 python -> python2.7
lrwxrwxrwx 1 root root 9 Apr 16 2018 python2 -> python2.7
-rwxr-xr-x 1 root root 3633480 Jul 9 16:51 python2.7
lrwxrwxrwx 1 root root 9 Oct 25 2018 python3 -> python3.6
-rwxr-xr-x 2 root root 4526456 Aug 20 17:12 python3.6
-rwxr-xr-x 2 root root 4526456 Aug 20 17:12 python3.6m
-rwxr-xr-x 2 root root 4906512 Apr 3 19:16 python3.7
-rwxr-xr-x 2 root root 4906512 Apr 3 19:16 python3.7m
-rwxr-xr-x 1 root root 1018 Oct 28 2017 python3-jsondiff
-rwxr-xr-x 1 root root 3661 Oct 28 2017 python3-jsonpatch
-rwxr-xr-x 1 root root 1342 May 1 2016 python3-jsonpointer
-rwxr-xr-x 1 root root 398 Nov 15 2017 python3-jsonschema
lrwxrwxrwx 1 root root 10 Oct 25 2018 python3m -> python3.6m
lrwxrwxrwx 1 root root 29 Apr 16 2018 pyversions -> ../share/python/pyversions.py
删除python的软链接,指向python3.7:
rm /usr/bin/python
ln -s /usr/bin/python3.7 /usr/bin/python
现在再看一下,已经改成我们想要的效果了。
root@ubuntu-1804-102:~/Python-3.8.0b4# python
Python 3.7.3 (default, Apr 3 2019, 19:16:38)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
root@ubuntu-1804-102:~/Python-3.8.0b4# python3
Python 3.8.0b4 (default, Sep 20 2019, 10:59:12)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>