源碼安裝Python3


源碼安裝Python3

一、安裝Python3需要的依賴包

[root@localhost ~]# yum install -y gcc make wget openssl openssl-devel readline readline-devel zlib* libffi-devel
  • 注釋:readlinebash shell 用的庫,包含許多使用功能
  • 后面預編譯可能會出現zipimport.ZipImportError: can't decompress data; zlib not available報錯,所以先安裝zlib*(包括需要的組件)
  • 后面編譯安裝可能會出現出現異常ModuleNotFoundError: No module named '_ctypes'報錯,所以先安裝libffi-devel

二、下載Python3源碼包、安裝

1. 下載Python3源碼包
[root@localhost ~]# wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz

2. 解壓
[root@localhost ~]# tar -xvf Python-3.8.1.tgz

3. 預編譯
[root@localhost ~]# cd Python-3.8.1
[root@localhost Python-3.8.1]# ./configure --prefix=/usr/local/python3 --with-ssl

4. 編譯安裝
[root@localhsot Python-3.8.1]# make
[root@localhsot Python-3.8.1]# make install

三、啟動Python3

[root@localhost ~]# /usr/local/python3/bin/python3
Python 3.8.1 (default, Nov 22 2020, 17:23:29) 
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

測試是否可以使用ssl模塊

[root@localhost ~]# python3 
Python 3.8.1 (default, Nov 22 2020, 17:23:29) 
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>        //沒有回顯什么,表示可以使用ssl模塊

四、快速啟動

在/usr/bin路徑下生成Python3的軟鏈接:ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@localhost ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@localhost ~]# python3 
Python 3.8.1 (default, Nov 22 2020, 17:23:29) 
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[root@localhost ~]#
[root@localhost ~]# which python3 
/usr/bin/python3


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM