linux环境下安装python 3
说明:
在linux环境下,都默认安装python 2的环境,由于python3在python2的基础上升级较大,所以安装python 3环境用于使用最新的python 3的语法。
安装过程:
1.下载,上传python 3源码包至服务器
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.执行配置检查,配置安装路径
[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编译环境。
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 <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