centos安装Python3

centos安装Python3

1、下载python3.5

wget https://www.Python.org/ftp/python/3.5.0/Python-3.5.0.tgz

注:如果在Linux中下载较慢,可以在Windows操作系统中去Python官网下载:https://www.python.org/downloads/release/python-350/

注意要下载Gzipped source tarball版本的,然后使用WinSCP将下载好的文件Python-3.5.0.tgz拖拽到linux中,后续步骤还是不变的。

2、解压

tar zxvf Python-3.5.0.tgz

3、进入Python-3.5.0文件夹

cd Python-3.5.0

4、创建安装目录

mkdir /usr/local/python3.5.0

5、配置安装位置

./configure --prefix=/usr/local/python3.5

注:如果没有安装C语言编译器会提示错误。如果出现错误,在联网的情况下使用 yum install gcc 命令安装gcc编译器,或者使用sudo yum install gcc-c++ 命令自动安装/升级gcc及其他依赖的包,详见下面的注释。

6、编译

make

7、安装

make install

8、下载并安装setuptools 18.5(这一步不安装也可以)

wget https://bootstrap.pypa.io/ez_setup.py -O - | python

注:如果提示错误 --no-check-certificate

在wget后加上 --no-check-certificate :wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | python

9、备份原有python命令执行文件

mv /usr/bin/python /usr/bin/pythonbak

10、创建新python软连接

ln -s /usr/local/python3.5/bin/python3.5 /usr/bin/python

11、查看python版本

python

[plain] view plain copy
[root@localhost Python-3.5.0]# python
Python 3.5.0 (default, Jul 15 2017, 07:13:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

12、修改yum配置文件
vim /usr/bin/yum
[plain] view plain copy
#!/usr/bin/python python修改为 python2.6
import sys
try:
import yum
except ImportError:
print >> sys.stderr, “”"\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

%s

Please install a package which provides this module, or
verify that the module is installed correctly.

It’s possible that the above module doesn’t match the
current version of Python, which is:
%s

If you cannot solve this problem yourself, please go to
the yum faq at:

注意:


Centos6.5(64位)下安装Python-3.5
执行./configure时报错:
configure: error: no acceptable C compiler found in $PATH


查看得知未安装合适的编译器。解决办法如下:

sudo yum install gcc-c++
(使用sudo yum install gcc-c++时会自动安装/升级gcc及其他依赖的包。)
重新执行以下命令
./configure --prefix=/usr/local/python3.5
make
make install
成功!

附带说明gcc与g++/gcc-c++的异同:
gcc为GNU Compiler Collection的缩写,可以编译C和C++源代码等,它是GNU开发的C和C++以及其他很多种语言的编译器(最早的时候只能编译C,后来很快进化成一个编译多种语言的集合,如Fortran、Pascal、Objective-C、Java、Ada、 Go等。)
gcc在编译C++源代码的阶段,只能编译C++源文件,而不能自动和C++程序使用的库链接(编译过程分为编译、链接两个阶段,源程序文件被编译成目标文件,多个目标文件连同库被链接成一个最终的可执行文件,可执行文件被加载到内存中运行)。因此,通常使用g++命令来完成C++程序的编译和连接,该程序会自动调用 gcc 实现编译。
g++也能编译C源代码,只不过把会把它当成C++源代码。后缀为.c的源文件,gcc把它当作是C程序,而g++把它当作是c++程序;后缀为.cpp的,两者都会认为是c++程序。注意,虽然c++是c的超集,但是两者对语法的要求是有区别的。

参考:https://blog.csdn.net/love666666shen/article/details/75188216

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值