python 2.7.11,下载链接  https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz,如下载速度太慢可在豆瓣pypi搜索下载https://pypi.doubanio.com/simple/

python升级到2.7.11可解决 内置的 socket库的setdefaulttimeout方法和multiprocessing库的manage队列冲突的问题,在2.7.3版本是需要改源码才能解决。问题如下

Traceback (most recent call last):
File "/usr/local/lib/python2.7/multiprocessing/process.py", line , in _bootstrap
self.run()
File "/usr/local/lib/python2.7/multiprocessing/process.py", line , in run
self._target(*self._args, **self._kwargs)
File "agentInstaller.py", line , in getInstallInfo
lock.acquire()
File "/usr/local/lib/python2.7/multiprocessing/managers.py", line , in acquire
return self._callmethod('acquire', (blocking,))
File "/usr/local/lib/python2.7/multiprocessing/managers.py", line , in _callmethod
self._connect()
File "/usr/local/lib/python2.7/multiprocessing/managers.py", line , in _connect
conn = self._Client(self._token.address, authkey=self._authkey)
File "/usr/local/lib/python2.7/multiprocessing/connection.py", line , in Client
answer_challenge(c, authkey)
File "/usr/local/lib/python2.7/multiprocessing/connection.py", line , in answer_challenge
message = connection.recv_bytes() # reject large message
IOError: [Errno ] Resource temporarily unavailable

解决问题可以修改源代码文件 /usr/local/lib/python2.7/multiprocessing/connection.py

     def Pipe(duplex=True):
'''
Returns pair of connection objects at either end of a pipe
'''
if duplex:
s1, s2 = socket.socketpair()
++ s1.setblocking(True)
++ s2.setblocking(True)
c1 = _multiprocessing.Connection(os.dup(s1.fileno()))
c2 = _multiprocessing.Connection(os.dup(s2.fileno()))
s1.close()
s2.close()
else:
fd1, fd2 = os.pipe()
c1 = _multiprocessing.Connection(fd1, writable=False)
c2 = _multiprocessing.Connection(fd2, readable=False) return c1, c2 def __init__(self, address, family, backlog=):
self._socket = socket.socket(getattr(socket, family))
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, )
++ self._socket.setblocking(True)
self._socket.bind(address)
self._socket.listen(backlog)
self._address = self._socket.getsockname()
self._family = family
self._last_accepted = None def accept(self):
s, self._last_accepted = self._socket.accept()
++ s.setblocking(True)
fd = duplicate(s.fileno())
conn = _multiprocessing.Connection(fd)
s.close()
return conn def SocketClient(address):
'''
Return a connection object connected to the socket given by `address`
'''
family = address_type(address)
s = socket.socket( getattr(socket, family) )
++ s.setblocking(True)
t = _init_timeout()

修改 /usr/local/lib/python2.7/test/test_multiprocessing.py

 assert sio.getvalue() == 'foo'

++ # Test interaction with socket timeouts - see Issue #
++ #
++
++ class TestTimeouts(unittest.TestCase):
++ @classmethod
++ def _test_timeout(cls, child, address):
++ time.sleep()
++ child.send()
++ child.close()
++ conn = multiprocessing.connection.Client(address)
++ conn.send()
++ conn.close()
++
++ def test_timeout(self):
++ old_timeout = socket.getdefaulttimeout()
++ try:
++ socket.setdefaulttimeout(0.1)
++ parent, child = multiprocessing.Pipe(duplex=True)
++ l = multiprocessing.connection.Listener(family='AF_INET')
++ p = multiprocessing.Process(target=self._test_timeout,
++ args=(child, l.address))
++ p.start()
++ child.close()
++ self.assertEqual(parent.recv(), )
++ parent.close()
++ conn = l.accept()
++ self.assertEqual(conn.recv(), )
++ conn.close()
++ l.close()
++ p.join()
++ finally:
++ socket.setdefaulttimeout(old_timeout)
++
++
++ testcases_other = [OtherTest, TestInvalidHandle, TestInitializers,
-- #- TestStdinBadfiledescriptor]
++ TestStdinBadfiledescriptor, TestTimeouts]

升级2.7.11的其他好处就去看官网描述吧。安装过程如下:

curl -k https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz -o python-2.7.11.tgz

yum -y install gcc gcc-c++ autoconf

yum -y install ncurses ncurses-devel

yum -y install mysql-devel

tar xf Python-2.7..tgz
cd Python-2.7./
./configure
make -j4 && make install

升级完重新打开secureCRT窗口

[root@master ~]# python
Python 2.7. (default, Nov , ::)
[GCC 4.4. (Red Hat 4.4.-)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

安装 pip,下载 get-pip.py

mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/bin/python /usr/bin/python
vim /usr/bin/yum 修改成 /usr/bin/python2.6.6
python get-pip.py
whereis pip
ln -s /usr/local/bin/pip2. /usr/bin/pip

安装readline

yum -y install readline-devel
yum -y install patch
yum -y install gcc python-devel zlib-devel openssl-devel libffi-devel pip install readline

若是使用 easy_install,则需要下载安装 setuptools 安装,下载链接 https://pypi.python.org/pypi/setuptools#downloads,安装过程缺少相关软件则同样下载安装包后上传至服务器安装,如果提示

MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
TypeError: __call__() takes exactly arguments ( given)

则需要注释掉该行代码,并补充如下代码

# MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
MARKER_EXPR = originalTextFor(MARKER_EXPR)("marker")

接着可能会遇到 “缺少 zlib 模块” 的情况,因为我们已经安装过 zlib-devel 模块和 zlib.x86_64 ,则只需要重新在 python 安装包中 make && make install 即可。

安装MySQLdb

pip install MySQL-python

或者源码安装

tar zxf MySQL-python-1.2..tar.gz
cd MySQL-python-1.2.
python setup.py build
python setup.py install

如果出现下面问题

>>> import MySQLdb
/usr/local/lib/python2./site-packages/MySQL_python-1.2.-py2.-linux-x86_64.egg/_mysql.py:: UserWarning: Module _mysql was already imported from /usr/local/lib/python2./site-packages/MySQL_python-1.2.-py2.-linux-x86_64.egg/_mysql.pyc, but /home/opd/tmpFiles/singleExec/MySQL-python-1.2. is being added to sys.path
Traceback (most recent call last):
File "<stdin>", line , in <module>
File "MySQLdb/__init__.py", line , in <module>
import _mysql
File "build/bdist.linux-x86_64/egg/_mysql.py", line , in <module>
File "build/bdist.linux-x86_64/egg/_mysql.py", line , in __bootstrap__
ImportError: libmysqlclient.so.: cannot open shared object file: No such file or directory
>>>

解决方法如下

# 根据最后提示,应该是找不着一个交libmysqlclient.so.18的文件,于是到mysql安装目录里找到这个文件并且做一个软连接到/usr/lib
ln -s /usr/local/mysql/lib/libmysqlclient.so. /usr/lib64/libmysqlclient.so.
# 如果是64系统则:
ln -s /usr/local/mysql/lib/libmysqlclient.so. /usr/lib64/libmysqlclient.so.

原创文章,转载请备注原文地址 http://www.cnblogs.com/lxmhhy/p/6030177.html

python版本升级的更多相关文章

  1. python版本升级及pip部署方法

    Python版本升级 CentOS 6.3自带的Python版本为2.6,首先需要升级到2.7版本.由于旧版本的Python已被深度依赖,所以不能卸载原有的Python,只能全新安装. 1.下载Pyt ...

  2. python 版本升级

    python 版本升级 升级python 查看python的版本 python -V Python 2.6.6 下载新版本 wget https://www.python.org/ftp/python ...

  3. Xshell 连接centOS虚拟机、centOS内置python版本升级

    Xshell 连接虚拟机 前置条件:VMware Workstation 12.5.1.Xshell 5 .  centOS 6.6 1.打开虚拟机,输入用户名和密码: 2.输出命令:ifconfig ...

  4. 【python】python版本升级,从2.6.6升级到2.7.13

    centos6.5系统自带了2.6.6版本的python,有时候为了项目上的需要,需要将python版本升级到2.7.13,下面介绍了如何进行升级. 说明:python从2.6升级到2.7会引发很多问 ...

  5. centos python版本升级到3.x

    Linux(CentOS)下将Python的版本升级为3.6.2的方法 1.检查确认系统的相关信息 查看内核版本[root@zstest1 ~]# cat /etc/redhat-release Ce ...

  6. python 版本升级(CentOS) 从2.6.6升级到2.7.6

    安装必须的包 yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readli ...

  7. linux python版本升级

    升级python版本的时候千万不能卸载python 2.6,再安装python2.7,这样会有无穷无尽的麻烦,保守的方式 是直接安装python2.7的源码包,也就是python两个版本共存.(因为C ...

  8. 【python】python版本升级2.6.6到2.7.3(CentOS release 6.2)

    一. 升级python到2.7.3 wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz tar -zxvf Python-2.7. ...

  9. linux的python版本升级

    可利用Linux自带下载工具wget下载,如下所示:     # wget http://www.python.org/ftp/python/2.7.3/Python-2.7.13.tgz 下载完成后 ...

随机推荐

  1. 【JUC】JDK1.8源码分析之ConcurrentLinkedQueue(五)

    一.前言 接着前面的分析,接下来分析ConcurrentLinkedQueue,ConcurerntLinkedQueue一个基于链接节点的无界线程安全队列.此队列按照 FIFO(先进先出)原则对元素 ...

  2. Hive UDF初探

    1. 引言 在前一篇中,解决了Hive表中复杂数据结构平铺化以导入Kylin的问题,但是平铺之后计算广告日志的曝光PV是翻倍的,因为一个用户对应于多个标签.所以,为了计算曝光PV,我们得另外创建视图. ...

  3. 最基本的javascript native carousel (1)

    原理:主要运用z-index这个属性来设置图片的展示和隐藏,代码如下: <!DOCTYPE html> <html lang="en"> <head& ...

  4. WebApi设置SessionState为Required

    public override void Init() { //在注册管道事件中 require session state //只能在引发“HttpApplication.AcquireReques ...

  5. 装饰模式 - Decorator 和 外观模式 - Facade

    装饰模式 Decorator,不改变接口但动态给对象加入责任,所需功能按顺序串联起来控制,比生成子类灵活. 外观模式 Facade,让接口更简单.为子系统中的一组接口提供一个一致的界面. 参考:

  6. 关于WebBrowser访问百度地图

    前段时间遇到一个困惑用WebBrowser访问百度地图的时候,百度会自动转至让下载sdk的页面,经过一个仁兄的点拨,可以改变WebBrowser的agent来骗过网站.经过试验成功.贴源码如下: st ...

  7. jQuery常用方法和函数

    jQuery 事件 bind() 方法:被选元素添加一个或多个事件处理程序,并规定事件发生时运行的函数 $(selector).bind({event:function, event:function ...

  8. CSS中详解hight属性

    目录结构: // contents structure [-] hight属性值类型一览表 height的%的使用 定义 实例 需要注意的 参考文章 hight属性值类型一览表 value descr ...

  9. JS图片自动和可控的轮播切换特效

    点击这里查看效果:http://hovertree.com/texiao/js/1.htm HTML文件代码如下: <!DOCTYPE html> <html xmlns=" ...

  10. JS实现自适应宽度的Tag切换

    效果体验:http://hovertree.com/texiao/js/3.htm 该效果使用纯JavaScript代码,实现TAB页切换效果,TAB标签根据内容自适应宽度,点击TAB标签切换内容页. ...