說明:
在linux環境下,都默認安裝python 2的環境,由于python3在python2的基礎上升級較大,所以安裝python 3環境用于使用最新的python 3的語法。
安裝過程:
1.下載,上傳python 3源碼包至服務器
2.解壓縮python 3壓縮包
[aiprd@hadoop3 softwares]$ lskibana-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]$lskibana-6.7.1-linux-x86_64.tar.gz Python-3.7.4 Python-3.7.4.tgz zookeeper-3.4.14.tar.gz
3.執行配置檢查,配置安裝路徑
[aiprd@hadoop3 Python-3.7.4]$ ./configure --prefix=/home/aiprd/app/python-3.7.4checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checkingfor python3.7... no
checkingforpython3... no
checkingforpython... python
checkingfor --enable-universalsdk... no
checkingfor --with-universal-archs... no
checking MACHDEP... checkingfor --without-gcc... no
checkingfor --with-icc... no
checkingfor gcc... no
checkingfor cc... no
checkingforcl.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編譯環境。
4.安裝gcc軟件包
yum install gcc
5.再次執行配置檢查,檢查通過
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 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 File"/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in File"/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in File"/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in File"/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in File"/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 20, in File"/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py", line 37, in File"/tmp/tmpry5ry5rh/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in File"/home/aiprd/softwares/Python-3.7.4/Lib/ctypes/__init__.py", line 7, in 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 todo
但是,發現ISO鏡像中,沒有該軟件包
[root@hadoop3 ~]# ls -l
total40
-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%]
再次進行編譯,安裝
makeclean #此處,需要先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
Python3.7.4
安裝完成。
文檔創建時間:2019年8月26日15:03:40