[root@localhost bin]# mkdir /usr/local/python3
[root@localhost bin]# cd /usr/local/python3
[root@localhost python3]# ll
total 0
[root@localhost python3]# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
#解压命令
[root@localhost python3]# tar -xvf Python-3.6.3.tgz
[root@localhost python3]# cd Python-3.6.3/
#python3Dir目录,这句话的大致目的就是把python的安装目录指定一下,这样的话,里面的一些bin目录、lib目录就都会存放在这个目录下面。
如果不指定这个安装目录的话,最后python的安装文件将分散到linux的默认目录,不在一块。我们指定安装目录,以后卸载的话直接删除目录就可以干净卸载了
[root@localhost Python-3.6.3]# ./configure --prefix=/usr/local/python3Dir --with-ssl
#第一个指定安装的路径,不指定的话,安装过程中可能软件所需要的文件复制到其他不同目录,删除软件很不方便,复制软件也不方便.
#第二个可以提高python10%-20%代码运行速度. --enable-optimizations,不必要不要用
#第三个是为了安装pip需要用到ssl,后面报错会有提到.
[root@localhost Python-3.6.3]# make
[root@localhost Python-3.6.3]# make install
# 如果make和make install报错,解决报错问题后一定要先执行make clean,然后在执行make && make install
[root@localhost Python-3.6.3]# make clean
[root@localhost Python-3.6.3]# cd /usr/local/python3Dir/
[root@localhost python3Dir]# ll
[root@localhost python3Dir]# cd /usr/bin
#然后输入以下命令 ,创建python3软链接
[root@localhost bin]# ln -s /usr/local/python3Dir/bin/python3 /usr/bin/python3
#然后输入以下命令 ,创建pip3软链接
[root@localhost bin]# ln -s /usr/local/python3Dir/bin/pip3.6 /usr/bin/pip3
ubuntu18.04自带python3.6升级为3.7
- 执行所有升级
# sudo apt update
# sudo apt install software-properties-common
- 安装编译Python源程序所需的包
# sudo add-apt-repository ppa:deadsnakes/ppa
# sudo apt update
# sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
# sudo apt install python3.7
- 下载Python 3.7源程序压缩包并安装
# wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
sudo rm /usr/bin/lsb_release
4、安装步骤参考最上面
安装python3.7
解决依赖(1,2,3不执行好像也行)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
https://www.python.org/downloads/ 下载 Gzipped source tarball
tar -xzvf xxx.tgz
不带--with-ssl, python3中将没有ssl模块
./configure --with-ssl
make
sudo make install
如果pip报错:ModuleNotFoundError: No module named ‘pip._internal.main’
执行一下命令
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificatesudo
python get-pip.py