查看当前已安装的Python版本
root@stormsha:/# python
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@stormsha:/# python2
Python 2.7.17 (default, Nov 7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@stormsha:/# python3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@stormsha:/# python3.7
Command 'python3.7' not found, but can be installed with:
apt-get安装Python3.7
$ sudo apt-get update
$ sudo apt-get install python3.7.7
$ python3.7
Python 3.7.7 (default, Jun 25 2020, 15:32:10)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
源码安装Python3.7
$ cd /home/tool # 这个路径是我的软件存放文件夹,下载位置无要求
$ wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tgz # 下载Python安装文件
$ tar -zxvf Python-3.7.7.tgz # 解压压缩包
$ mkdir -p /usr/local/python3.7 # 这个/usr/local路径是我软件安装位置文件夹,创建python3.7安装目录
$ cd Python-3.7.7 # 进入解压后目录
$ ./configure --prefix=/usr/local/python3.7 # 指定安装位置
$ make # 编译Python
$ make install # 安装Python
$ mkdir -p /usr/bin/python3.7 # 创建一个系统目录
$ ln -s /usr/local/python3.7/bin/python3 /usr/bin/python3.7 # 把Python映射到Linux系统目录下
$ echo $PATH
/usr/bin:/usr/lib/jvm/java-11-openjdk-amd64/bin:/usr/bin:/usr/lib/jvm/java-11-openjdk-amd64/bin:/usr/jvm/jdk1.8.0_231/bin:/usr/jvm/jdk1.8.0_231/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/bin:/root/bin:/usr/local/python3.7/bin:/root/bin:/usr/local/python3.7/bin
$ /root/bin:/usr/local/python3.7/bin # Python3.7的环境变量,不做系统目录映射,这里是查不到的
$ vim /etc/profile # 编辑环境变量,添加如下两行
export Python_HOME=/usr/local/python3.7
export PATH=$Python_HOME/bin
$ source /etc/profile
$ python3.7
Python 3.7.7 (default, Jun 25 2020, 15:32:10)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
安装PIP3
$ sudo apt update
$ sudo apt install python3-pip
$ pip3 --version
转载请注明: StormSha » Ubuntu安装Python3