【Python 开发】第二篇 :Python安装

一、python3.x安装

1)由于centos7原本就安装了Python2,而且这个Python2不能被删除,因为有很多系统命令,比如yum都要用到。

官网:https://www.python.org/

[root@host130 ~]# python
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@host130 ~]# which python
/usr/bin/python
[root@host130 ~]# 

二、源码安装python3.7  

2)通过源码安装python3.x,我选择是安装python3.7
2.1 下载依赖包
[root@host130 ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel2.2 
[root@host130 src]# pwd 
/usr/local/src
下载不同版本的Python3,我下载的是Python3.7
[root@host130 src]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0rc1.tgz 
[root@host130 src]# tar -zxvf Python-3.7.0rc1.tgz
[root@host130 src]# cd Python-3.7.0rc1/
[root@host130 Python-3.7.0rc1]# ls
aclocal.m4 configure.ac install-sh
Mac Objects Programs setup.py config.guess Doc Lib Makefile.pre.in Parser pyconfig.h.in
Tools config.sub Grammar LICENSE Misc PC Python configure Include m4 Modules PCbuild README.rst
[root@host130 Python-3.7.0rc1]# ./config
config.guess config.sub configure
[root@host130 Python-3.7.0rc1]# ./configure --prefix=/usr/local/python3
[root@host130 Python-3.7.0rc1]# make && make install
[root@host130 Python-3.7.0rc1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@host130 Python-3.7.0rc1]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[root@host130 Python-3.7.0rc1]# python3
Python 3.7.0rc1 (default, Sep 18 2018, 18:22:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit Use exit() or Ctrl-D (i.e. EOF) to exit >>> 
参考博客:https://www.cnblogs.com/dangkai/p/9394363.html

三、编译时报错处理

o module named '_ctypes'    参考博客:https://blog.csdn.net/qq_36416904/article/details/79316972

的解决办法: 原因:3.7版本需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可。 [root@host130 Python-3.7.0rc1]# yum -y install libffi-devel [root@host130 Python-3.7.0rc1]# make && make install 安装成功: [root@host130 Python-3.7.0rc1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3 [root@host130 Python-3.7.0rc1]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 [root@host130 Python-3.7.0rc1]# python3 Python 3.7.0rc1 (default, Sep 18 2018, 18:22:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit Use exit() or Ctrl-D (i.e. EOF) to exit >>>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值