因爲centos7本來就安裝了Python2,並且這個Python2不能被刪除,由於有不少系統命令,好比yum都要用到。html
[root@VM_105_217_centos Python-3.6.2]# python Python 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
輸入Python命令,查看能夠得知是Python2.7.5版本python
輸入mysql
which python
能夠查看位置,通常是位於/usr/bin/python目錄下。linux
下面介紹安裝Python3的方法sql
首先安裝依賴包centos
yum -y groupinstall "Development tools" yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
而後根據本身需求下載不一樣版本的Python3,我下載的是Python3.6.2服務器
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
#其餘版本地址:https://www.python.org/ftp/python/
若是速度不夠快,能夠直接去官網下載,利用WinSCP等軟件傳到服務器上指定位置,個人存放目錄是/usr/local/python3,使用命令:測試
mkdir /usr/local/python3
創建一個空文件夾centos7
而後解壓壓縮包,進入該目錄,安裝Python3spa
tar -xvJf Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install
最後建立軟連接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
在命令行中輸入python3測試
安裝 mysql:
pip3 install mysqlclient