centos7.3安裝python3.9
阿新 • • 發佈:2021-10-20
最近伺服器需要安裝python3.7環境,centos7.3預設最高可以安裝python3.6版本,3.7版本以上需要另行安裝依賴環境,測試安裝後,發現通過以下步驟可以較快完成安裝,以3.9.0為例:
準備:首先需要下載python3.9.0的安裝包
一、安裝python3.9所需依賴包
依賴包主要有:zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
可以通過yum進行安裝,如下:
[root@localhost ~]# 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 libffi-develer
二、安裝python3.9.0
1、將已經下載的好的python3.9.0的tar包上傳至伺服器
2、新建一個資料夾,用於存放python3.9
[root@localhost local]# mkdir python3.9
3、將Python-3.9.0.tgz包進行解壓
[root@localhost local]# tar -zxvf Python-3.9.0.tgz
4、編譯安裝(本例將其安裝至/usr/local/python3.9下)
[root@localhost local]# cd Python-3.9.0/ [root@localhost Python-3.9.0]# ./configure --prefix=/usr/local/python3.9 [root@localhost Python-3.9.0]# make && make install
安裝成功後顯示如下位元組
5、建立軟連結
軟連結類似Windows下的快捷方式,正常應該新增python3.9的環境變數,但因為系統預設已經安裝python2.7,所以只建立一個軟連結,如果不想建立軟連結,也可以命令別名,在~/.bashrc檔案里加alias python3='具體路徑' 。本文以增加軟連結為例:
[root@localhost Python-3.9.0]# ln -s /usr/local/python3.9/bin/python3.9 /usr/bin/python3 [root@localhost Python-3.9.0]# ln -s /usr/local/python3.9/bin/pip3.9 /usr/bin/pip3
6、測試
[root@localhost Python-3.9.0]# python3 Python 3.9.0 (default, Oct 20 2021, 16:17:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit()
至此,安裝完成
轉載請註明出處:https://www.cnblogs.com/tushengjin/p/15428737.html