Python 3 安裝
阿新 • • 發佈:2018-12-24
Linux下的Python3安裝:
如果本機安裝了python2,儘量不要管他,使用python3執行python指令碼就好,因為可能有程式依賴目前的python2環境,
比如yum!!!!!
不要動現有的python2環境!
一、安裝python3.6
1.安裝依賴環境
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
2.下載Python3
# 想下載到那個資料夾下就先進入到那個資料夾下——cd /home/download
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
3.解壓檔案
# 安裝包路徑下
tar -xvf Python-3.6.0.tgz
解壓下載好的Python-3.x.x.tgz包(具體包名因你下載的Python具體版本不不同⽽而不不同,如:我下載的是Python3.6.0.那我這里就是Python-3.6.0.tgz)
4.進入解壓後的目錄,編譯
cd Python-3.6.0 ./configure --prefix=/usr/local/python3
5.安裝
make
make install
6.建立python3的軟連結
# 根目錄下
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
7.並將/usr/local/python3/bin加入PATH
vim ~/.bash_profile
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/python3/bin export PATH
按ESC,輸入:wq回車退出。
修改完記得執行行下面的命令,讓上一步的修改生效:
source ~/.bash_profile
8.檢查Python3及pip3是否正常可用:
python3 -V
# Python 3.6.0
pip3 -V
# pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
9.不行的話在建立一下pip3的軟連結(我也不清楚這一步有什麼用,沒遇到過)
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3