ubuntu16.04 安装 python3.7

2019-01-25 02:46:36   Python

  python  

python源码下载
https://www.python.org/downloads/release/python-372/

解压源码
tar -zxvf Python-3.7.0.tgz -C ~

安装源码编译所需的各种依赖库:(Ubuntu16.04环境下)

sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libffi-dev libc6-dev

./configure —prefix=/opt/python3.7 —enable-optimizations //配置

make -j 4 编译

sudo make 安装

sudo make install

或者sudo make && make install 如果提示文件不能创建就分开执行这段话

修改python默认版本

安装完以后,,默认应该是2.7 修改默认版本先打开这个文件 ~/.bashrc

  1. ls /usr/bin/python*
  2. /usr/bin/python /usr/bin/python3 /usr/bin/python3m
  3. /usr/bin/python2 /usr/bin/python3.5 /usr/bin/python-mkdebian
  4. /usr/bin/python2.7 /usr/bin/python3.5m
  5. python 显示2.7
  6. vim ~/.bashrc
  7. 增加新的别名 alias python='/usr/bin/python3.5'
  8. 重新加载 . ~/.bashrc
  9. 检查版本就变成了 3.5