說明:python
在linux環境下,都默認安裝python 2的環境,因爲python3在python2的基礎上升級較大,因此安裝python 3環境用於使用最新的python 3的語法。linux
安裝過程:bootstrap
1.下載,上傳python 3源碼包至服務器centos
2.解壓縮python 3壓縮包服務器
[aiprd@hadoop3 softwares]$ ls kibana-6.7.1-linux-x86_64.tar.gz Python-3.7.4.tgz zookeeper-3.4.14.tar.gz [aiprd@hadoop3 softwares]$ tar -zxf Python-3.7.4.tgz [aiprd@hadoop3 softwares]$ ls kibana-6.7.1-linux-x86_64.tar.gz Python-3.7.4 Python-3.7.4.tgz zookeeper-3.4.14.tar.gz
3.執行配置檢查,配置安裝路徑app
[aiprd@hadoop3 Python-3.7.4]$ ./configure --prefix=/home/aiprd/app/python-3.7.4 checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python3.7... no checking for python3... no checking for python... python checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... checking for --without-gcc... no checking for --with-icc... no checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/home/aiprd/softwares/Python-3.7.4': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
配置檢查報錯,沒有C編譯環境。oop
4.安裝gcc軟件包ui
yum install gccspa
5.再次執行配置檢查,檢查經過.net
6.編譯,安裝
make && make install
再次報錯:
Traceback (most recent call last): File "/home/aiprd/softwares/Python-3.7.4/Lib/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/home/aiprd/softwares/Python-3.7.4/Lib/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/aiprd/softwares/Python-3.7.4/Lib/ensurepip/__main__.py", line 5, in <module> sys.exit(ensurepip._main()) File "/home/aiprd/softwares/Python-3.7.4/Lib/ensurepip/__init__.py", line 204, in _main default_pip=args.default_pip, File "/home/aiprd/softwares/Python-3.7.4/Lib/ensurepip/__init__.py", line 117, in _bootstrap return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths) File "/home/aiprd/softwares/Python-3.7.4/Lib/ensurepip/__init__.py", line 27, in _run_pip import pip._internal zipimport.ZipImportError: can't decompress data; zlib not available make: *** [install] Error 1
安裝zlib-devel軟件包
yum install zlib-devel
7.再次編譯,安裝,報下面的錯誤
import pip._internal File "/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module> File "/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module> File "/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module> File "/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module> File "/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module> File "/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 20, in <module> File "/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py", line 37, in <module> File "/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module> File "/home/aiprd/softwares/Python-3.7.4/Lib/ctypes/__init__.py", line 7, in <module> from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes' make: *** [install] Error 1
安裝libffi-devel軟件包
[root@hadoop3 Packages]# yum install libffi-devel -y Loaded plugins: product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Install Process No package libffi-devel available. Error: Nothing to do
可是,發現ISO鏡像中,沒有該軟件包
下載libffi-devel的RPM包,進行安裝,下載地址:http://rpmfind.net/linux/centos/6.10/os/x86_64/Packages/libffi-devel-3.0.5-3.2.el6.x86_64.rpm
[root@hadoop3 ~]# ls -l total 40 -rw-------. 1 root root 1031 Feb 19 2019 anaconda-ks.cfg -rw-r--r--. 1 root root 10475 Feb 19 2019 install.log -rw-r--r--. 1 root root 3161 Feb 19 2019 install.log.syslog -rw-r--r-- 1 root root 18000 Aug 26 14:56 libffi-devel-3.0.5-3.2.el6.x86_64.rpm [root@hadoop3 ~]# rpm -ivh libffi-devel-3.0.5-3.2.el6.x86_64.rpm warning: libffi-devel-3.0.5-3.2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:libffi-devel ########################################### [100%]
再次進行編譯,安裝
make clean #此處,須要先make clean,而後從新configure,不然即便libffi-devel軟件包已經安裝,仍然會報錯。 ./configure --prefix=/home/aiprd/app/python-3.7.4 make && make install
Looking in links: /tmp/tmpr5iivfh5 Collecting setuptools Collecting pip Installing collected packages: setuptools, pip Successfully installed pip-19.0.3 setuptools-40.8.0
8.查看python版本
[aiprd@hadoop3 python-3.7.4]$ bin/python3 --version Python 3.7.4
安裝完成。
文檔建立時間:2019年8月26日15:03:40