Centos/Linux 下升级python2.7至3.5.0
(一) 安装Python3.5
(1)在安装python之前,因为linux系统下默认没有安装wget,gcc,首先安装wget,gcc:
[root@node6 python_scripts]# yum install wget
[root@node6 python_scripts]# yum install gcc
(2)安装依赖:
!!!在编译之前需要安装一些必须的依赖,否则当报错的时候还得重新编译
yum install openssl-devel -y
yum install zlib-devel -y
(3)利用wget下载python3.5.0的安装文件并解压缩:
[root@node6 python_scripts]#wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
[root@node6 python_scripts]# ls
Python-3.5..tgz
[root@node6 python_scripts]# tar xvf Python-3.5..tgz
[root@node6 python_scripts]# ls
Python-3.5. Python-3.5..tgz
[root@node6 Python-3.5.]# cd Python-3.5.
(4)编译:
[root@node6 Python-3.5.]# ./configure --prefix=/usr/local/python3.
[root@node6 Python-3.5.]# make
[root@node6 Python-3.5.]# make install
[root@node6 Python-3.5.]mv /usr/bin/python /usr/bin/python_bak
[root@node6 Python-3.5.]ln -s /usr/local/python3./bin/python3. /usr/bin/python
(5)此时执行phthon可以看到3.5已经运行:
[root@node6 python_scripts]# python
Python 3.5. (default, Jul , ::)
[GCC 4.8. (Red Hat 4.8.-)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
(6) 此时yum的运行会报错,如下操作可以恢复yum:
修改yum文件
、cd /usr/bin
、ls -l yum*
会显示出“yum、yum-builddep、yum-config-manager、yum-debug-dump、yum-debug-restore、yumdownloader、yum-groups-manager”这7个yum开头的文件,这7个文件都是脚本文件,其第一行为:
#!/usr/bin/python
或
#!/usr/bin/python -tt
将“python”改为“python2.7”。
我们试着安装一个文件:
[root@vnode33 bin]# yum install tcpreplay
发现系统仍然报错:
Is this ok [y/d/N]: y
Downloading packages:
File "/usr/libexec/urlgrabber-ext-down", line
except OSError, e:
^
SyntaxError: invalid syntax
找到该文件[root@vnode33 libexec]# vi /usr/libexec/urlgrabber-ext-down
修改/usr/bin/python为/usr/bin/python2.7
可以安装成功了:
Is this ok [y/d/N]: y
Downloading packages:
tcpreplay-4.1.-.el7.x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tcpreplay-4.1.-.el7.x86_64 /
Verifying : tcpreplay-4.1.-.el7.x86_64 / Installed:
tcpreplay.x86_64 :4.1.-.el7 Complete!
或者也可以用以下的方法:
./configure --prefix=/opt/python #因为centos自带python,为了不影响原有系统,我这里是另外安装到新目录 make install 进行安装 ln -s /opt/python/bin/python3. /usr/bin/python3 #软连接到系统path所指向的一个目录中,使之成为系统命令 ln -s /opt/python/bin/pip3. /usr/bin/pip3 ln -s /opt/python/bin/easy_install-3.4 /usr/bin/easy_install3
(二)安装pip3:
(1)首先下载,安装依赖setuptools
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6.tar.gz
python3 setup.py build
python3 setup.py install
(2)安装pip3
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0..tar.gz
cd pip-8.0.
python3 setup.py build
python3 setup.py install
安装完成之后我们再来查看python3.5的bin目录下都有什么东西:
[root@vnode33 usr]# cd /usr/local/python3./bin/
[root@vnode33 bin]# ls
2to3 easy_install idle3 pip pip3. pydoc3. python3. python3.5m python3-config pyvenv-3.5
2to3-3.5 easy_install-3.5 idle3. pip3 pydoc3 python3 python3.-config python3.5m-config pyvenv
为pip3创建链接:
[root@vnode33 bin]# ln -s /usr/local/python3./bin/pip3 /usr/bin/pip
现在可以用了:
[root@vnode33 bin]# pip Usage:
pip <command> [options] Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
help Show help for commands. ...
(3)安装Twisted
Linux上设置https proxy并安装:
本机因从网络下载包时需要代理,故需要如下命令:
export https_proxy=135.251.33.31:
export http_proxy=135.251.33.31:
export ftp_proxy=135.251.33.31:
然后下载安装:
wget https://pypi.python.org/packages/source/T/Twisted/Twisted-15.2.1.tar.bz2
tar -xjvf Twisted-15.2..tar.bz2
cd Twisted-15.2./
python setup.py install
检查是否安装成功:
[root@vnode33 ~]# python
Python 3.5. (default, Feb , ::)
[GCC 4.8. (Red Hat 4.8.-)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import twisted
>>>
(4)安装Scrapy
pip install Scrapy
这个时候安装成功了,但是运行scrapy时报错
再重新安装下Twisted最新的版本:
wget https://twistedmatrix.com/Releases/Twisted/17.1/Twisted-17.1.0.tar.bz2
tar -xjvf Twisted-17.1..tar.bz2
cd Twisted-17.1./
python setup.py install
再运行scrapy发现已经好了:
[root@vnode33 bin]# ./scrapy
Scrapy 1.3. - no active project Usage:
scrapy <command> [options] [args] Available commands:
bench Run quick benchmark test
commands
fetch Fetch a URL using the Scrapy downloader
genspider Generate new spider using pre-defined templates
runspider Run a self-contained spider (without creating a project)
settings Get settings values
shell Interactive scraping console
startproject Create new project
version Print Scrapy version
view Open URL in browser, as seen by Scrapy [ more ] More commands available when run from project directory Use "scrapy <command> -h" to see more info about a command
还需要做一个软链接让scrapy命令全局可用:
ln -s /usr/local/python3./bin/scrapy /usr/bin/scrapy
试试在Python中导入scrapy:
Python 3.5. (default, Feb , ::)
[GCC 4.8. (Red Hat 4.8.-)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from scrapy.spider import BaseSpider
__main__:: ScrapyDeprecationWarning: Module `scrapy.spider` is deprecated, use `scrapy.spiders` instead
>>> from scrapy.spiders import BaseSpider
安装scrapy过程中有三步不确定是否需要,附录如下:
1,libxml2
wget ftp://xmlsoft.org/libxml2/libxml2-git-snapshot.tar.gz
tar -zxvf libxml2-git-snapshot.tar.gz
cd libxml2-2.9./
./configure
make
make install
2,libxlst
wget http://xmlsoft.org/sources/libxslt-1.1.28.tar.gz
tar -zxvf libxslt-1.1..tar.gz
cd libxslt-1.1./
./configure
make
make install
3,cryptography
wget ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
tar -zxvf libffi-3.2..tar.gz
cd libffi-3.2.
./configure
make
make install
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
wget ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
tar -zxvf libffi-3.2..tar.gz
cd libffi-3.2.
./configure
make
make install
Windows7下安装scrapy:
先下载python-3.5.2.exe 双击文件安装成功:
然后直接安装scrapy,找到pip文件的目录:
cd C:\Users\xxx\AppData\Local\Programs\Python\Python35-\Scripts
pip install scrapy
安装成功后测试下:
C:\Users\xxx>python
Python 3.5. (v3.5.2:4def2a2901a5, Jun , ::) [MSC v. bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from scrapy.spiders import BaseSpider
>>> exit()
(三)IDLE支持方向键:
(1)安装readline
pip install readline
但是有如下报错:
gcc: error: readline/libreadline.a: No such file or directory
解决方法:
yum install readline-devel
yum install patch
再重新configure、make、make install python3.
Centos/Linux 下升级python2.7至3.5.0的更多相关文章
- Linux下安装python-2.7 先zlib
2018-04-25 发布 Linux下安装python-2.7 python 1.1k 次阅读 · 读完需要 25 分钟 1 安装依赖的库 yum -y install python-deve ...
- centos Linux下磁盘管理 parted,df ,du,fdisk,partprobe,mkfs.ext4,mount,/etc/fstab,fsck,e2fsck,mk2efs,tmpfs ,nr_inodes, LVM,传统方式扩容文件系统 第七节课
centos Linux下磁盘管理 parted,df ,du,fdisk,partprobe,mkfs.ext4,mount,/etc/fstab,fsck,e2fsck,mk2efs,tmpf ...
- CentOS linux下安装和配置Apache+SVN(用浏览器http方式访问SVN目录)
在CentOS linux下安装SVN,我们可以进行以下步骤: 第一步:安装CentOS Linux操作系统,并在CentOS安装进行的同时,自定义安装这一步,一定要勾选Subversion(在“开发 ...
- centos/linux下的安装Maven
1.保证该项目安装了JDK 请在系统中输入java -version查看该命令是否存在 如果没有安装JDK请移步到Centos/linux下的JDK安装 2.下载Maven wget http://m ...
- centos/linux下的安装Tomcat
1.启动tomcat时候需要JDK依赖 如果没有安装的请移步到该链接Centos/linux下的JDK安装 2.从官网上下载tomcat压缩包 wget -c http://apache.fayea. ...
- CentOS/Linux下设置IP地址
CentOS/Linux下设置IP地址 1:临时修改:1.1:修改IP地址# ifconfig eth0 192.168.100.100 1.2:修改网关地址# route add default g ...
- CentOS 7下升级MySQL5.7.23的一个坑
发现CentOS 7下升级MySQL5.7.23的一个坑,以前面升级到MySQL 5.7.23的一个集群为例 在我们环境下打开文件描述符个数的参数open_files_limit在MySQL 5.6. ...
- 你的centos/linux下有多个php.ini,不确定是哪个时
你的centos/linux下有多个php.ini,不确定是哪个时,但是你自己知道,你的php安装目录. 比如我的php安装目录是 /usr/local/php 那么可以通过命令来查找php.ini的 ...
- 【转】Mac下升级python2.7到python3.6
1. 前言 Mac系统自带python2.7,本文目的是将自带的python升级到3.6版本. 网上有本多的做法是让python2.7和python3.X两个版本共存,博主并不知道,是两版本共存好,还 ...
随机推荐
- jquery 插件学习
练习jquery上的一个插件编写 1.标准的3个基本内容,根目录里面创建2个文件夹(存放css和js)和1个html页面文件: 2.测试的主html页面代码 <!DOCTYPE html> ...
- 论反向ajax
在讨论反向ajax之前,说一下我大二写的一个聊天程序,通过前端ajax不断向服务器发送请求(通过http连接),服务器进行一次数据库查询,然后返回结果,断开与服务器的链接(绝大部分都是无用的结果)来维 ...
- .net第三方数据库物理卡号同步功能实现
本地数据库用的是Oracle,第三方数据库是SQL Server,连接字符串保存在web.config里面. 第三方数据库为增量,每次读取要记录读取的最大位置.我是保存在本地txt文件里面. //保存 ...
- H5测试(转载)
可能有些朋友不明白啥是H5,但其实生活中我们经常会碰到. 比如,你经常收到的朋友虐狗第一式—结婚请贴. 你的朋友圈,可能会经常看到宝妈们虐狗第二式—晒可爱宝宝的相册. 你有可能也收到过这样,非常直观, ...
- QK对中断的特殊处理
1.QK的特性 QK(Quntum Kernel)是一个抢占式.基于优先级实时微内核.一个多任务调度器: QK不同于传统的RTOS,是非阻塞的,并且只用了一个stack: 对QK中的任务来说,采用了I ...
- 使用ntp协议同步本地时间(C语言)
使用ntp协议同步本地时间 同步服务器使用的东北大学网络授时服务:ntp.neu.edu.cn更多ntp服务器 http://www.ntp.org.cn/ 源代码来自网络,经本人精简ntp部分,供大 ...
- python学习笔记二:if语句及循环语句,断点,模块,pyc
if语句 注意:语句块中的内容要强制缩进,否则出错.IndentationError,缩进错误 所有代码,如果是顶级的,必须顶格写,前面不能有空格 if … : … elif … : … else: ...
- ubuntu解决网易云无法打开
最近首次入手ubuntu18 摸索了很久,当然网易云是不可缺少的一部分,在配置好各种环境+程序后,也找到了解决网易云的方法了. 首先安装好网易云 默认情况下需要在终端使用 sudo 才能运行 解决的办 ...
- R语言爬虫:CSS方法与XPath方法对比(表格介绍)
css 选择器与 xpath 用法对比 目标 匹配节点 CSS 3 XPath 所有节点 ~ * //* 查找一级.二级.三级标题节点 <h1>,<h2>,<h3> ...
- linux 网络编程 2---(TCP编程)
流程 服务器:server 创建套接字 socket( ) 填充服务器网络信息结构体 sockaddr_in 将套接字与服务器网络信息结构体绑定 bind( ) 将套接字设置为被动监听状态 liste ...