版权声明:本文为博主原创文章,欢迎扩散,扩散请务必注明出处。
在Linux 7版本中,系统默认自带python2.x的版本。随着python3.x的不断普及与广泛使用,越来越多的应用程序基于Python3开发。本文主要描述在Linux 7下使用编译方式安装Python 3。
# more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
# python --version
Python 2.7.5
# yum install gcc -y
# yum install zlib* -y
# cd /usr/local/src
# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
# tar -xf Python-3.6.4.tgz
# cd Python-3.6.4/
# ./configure
# make && make install
# ln -sv /usr/local/src/Python-3.6.4 /usr/local/python3
# /usr/local/python3/python --version
Python 3.6.4
### pip3也被一同安装
# pip3 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
# ln -sv /usr/local/python3/python /usr/bin/python3
# python3
Python 3.6.4 (default, Sep 16 2018, 17:28:09)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello Python")
hello Python
# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
如上,两个版本同时并存
错误1
configure: error: in `/usr/local/src/Python-3.6.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
# yum install gcc -y
错误2
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
# yum install zlib* -y