centos安裝python3.9.0 1.先決條件: sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel 2.下載: 各版本地址:https://www.python.org/ftp/python wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz 3.解壓: tar xzf Python-3.9.0.tgz 4.安裝: cd Python-3.9.0 sudo ./configure --enable-optimizations sudo make altinstall 5.創建虛擬環境(for flask project,僅安裝python則忽略) virtualenv -p /usr/local/bin/python3.9 venv source ./venv/bin/activate pip install -r requirements.txt 遇到的問題: 1.yum源問題導致gcc安裝失敗 (1)執行sudo ./configure --enable-optimizations報缺少C編譯器 configure: error: in `/opt/python39/Python-3.9.0': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details 嘗試執行:yum install gcc 時報yum庫libgomp版本沖突 Error: Multilib version problems found. This often means that the root cause is something else and multilib version checking is just pointing out that there is a problem. Eg.: ... ... Protected multilib versions: libgomp-4.8.5-4.el7.i686 != libgomp-4.8.5-36.el7_6.2.x86_64 rpm -qa|grep libgomp: libgomp-4.8.5-36.el7_6.2.x86_64 嘗試執行yum install gcc --setopt=protected_multilib=false忽略protected multilib,依然報錯 Transaction check error: package libgomp-4.8.5-36.el7_6.2.x86_64 (which is newer than libgomp-4.8.5-4.el7.i686) is already installed 目測是該yum源中libgomp版本還是不符合gcc依賴,只好嘗試升級yum源到國內阿里源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum clean all yum makecache vi /etc/yum.repos.d/CentOS-Base.repo #將所有http改為https,注意備份該文件(vi替換命令 :1,$s/http/https/g) yum update yum install gcc 2.升級gcc版本 centos7使用yum install gcc后默認安裝版本是gcc 4.8.5,版本比較低,升級gcc版本: sudo yum install centos-release-scl sudo yum install devtoolset-7 scl enable devtoolset-7 bash gcc --version # 升級后為7.3.1 3.pip install -r requirements.txt報錯,降低setuptools版本,新版本setuptools移除了Feature Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-install-wduw3u48/markupsafe/setup.py", line 6, in <module> from setuptools import setup, Extension, Feature ImportError: cannot import name 'Feature' from 'setuptools' 這個通常會在安裝 Flask 項目的依賴時發生,因為 MarkupSafe 是 Flask 的依賴之一 原因是因為 Python 打包工具 setuptools 在 46.0.0 版本刪掉了棄用的 Feature, 更新 MarkupSafe 到最新版本 pip install --upgrade pip setuptools==45.2.0 4.啟動項目報警告 UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError 重新編譯python: sudo yum install -y xz-devel sudo ./configure --enable-optimizations sudo make altinstall 5.啟動項目報警告 RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used remember ... it is not a bug, it's a feature 這個是gunicorn 19.x有可能報的問題,可以選擇升級gunicorn解決: pip install gunicorn==20.0.4 參考: https://tecadmin.net/install-python-3-9-on-centos/ (安裝python39) https://developer.aliyun.com/article/704987 (配置阿里鏡像) https://www.itcoder.tech/posts/how-to-install-gcc-compiler-on-centos-7/ (升級gcc) https://zhuanlan.zhihu.com/p/127820010 (MarkupSafe報錯) https://stackoverflow.com/questions/57743230/userwarning-could-not-import-the-lzma-module-your-installed-python-is-incomple(lzma問題) https://askubuntu.com/questions/1216292/python3-runtimewarning-line-buffering-buffering-1-isnt-supported-in-binary-m (gunicorn line buffer問題)