登录        注册
本站基于Django开发,源码 Github 欢迎 Fork、Star。由于站点升级导致评论区留言信息丢失,欢迎前来发表新的评论

Ubuntu安装Python3

Python stormsha 66浏览 19喜欢 0评论

查看当前已安装的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

发表我的评论

表情
(0)个小伙伴在吐槽|0条评论
暂时没有评论,欢迎来尬聊!