Ubuntu 18.04 安装 python3.7

Ubuntu 18.04系统内置了Python 3.6和Python 2.7版本,以下是在Ubuntu 18.04系统中安装Python 3.7版本的方法。

1. 执行所有升级

# sudo apt-get update
# sudo apt-get upgrade -y

  
  
  • 1
  • 2

2. 安装编译Python源程序所需的包

# sudo apt-get install build-essential -y
# sudo apt-get install libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev -y
# sudo apt-get install zlib1g-dev

  
  
  • 1
  • 2
  • 3

3. 下载Python 3.7源程序压缩包

# wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz

  
  
  • 1

4. 解压缩

# tar -xzvf Python-3.7.1.tgz

  
  
  • 1

5. 配置

# cd Python-3.7.1
# ./configure --enable-optimizations

  
  
  • 1
  • 2

执行上述语句将启用代码的发布版本,可以优化二进制文件以更好的更快的运行,但是需要运行测试,编译时需要花费一些时间(大约半小时),也可以不进行这一项配置。

6. 编译和安装Python 3.7

# sudo make
# sudo make install

  
  
  • 1
  • 2

7. 查看Python版本

# python3
Python 3.7.1 (default, Nov 21 2018, 16:35:49) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

  
  
  • 1
  • 2
  • 3
  • 4
  • 5

出现上述语句说明安装成功。

8. 升级pip和更换pip源

# sudo pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# pip3 install --upgrade pip

  
  
  • 1
  • 2

参考

  1. Install Python 3.7.0 on Ubuntu 18.04/Debian 9.5
  2. 清华大学pypi 镜像使用帮助
                                </div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-e44c3c0e64.css" rel="stylesheet">
发布了184 篇原创文章 · 获赞 70 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/qq_31939617/article/details/100781281