CENTOS 6.X 系列默认安装的 Python 2.6 ,目前开发中主要是使用 Python 2.7 ,这两个版本之间仍是有很多差别的,程序在 Python 2.6 下常常会出问题。html
好比: re.sub
函数 ,2.7 支持 flags
参数,而 2.6 却不支持。python
因此,打算安装 Python 2.7 来运行 Flask 应用程序,但 2.6 不能删除,由于系统对它有依赖。sql
由于 Flask 应用程序可能使用能 Sqlite 数据库,因此这个得装上(以前由于没装这个,致使 Python 没法导入 sqlite3 库。数据库
固然,也能够从源码编译安装。bootstrap
yum install sqlite-devel -y
wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz tar xf Python-2.7.8.tgz cd Python-2.7.8 ./configure --prefix=/usr/local make && make install
安装成功以后,你能够在 /usr/local/bin/python2.7
找到 Python 2.7。centos
这里须要注意,必定要使用 python2.7 来执行相关命令。app
# First get the setup script for Setuptools: wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py # Then install it for Python 2.7 : python2.7 ez_setup.py # Now install pip using the newly installed setuptools: easy_install-2.7 pip # With pip installed you can now do things like this: pip2.7 install [packagename] pip2.7 install --upgrade [packagename] pip2.7 uninstall [packagename]
# Install virtualenv for Python 2.7 and create a sandbox called my27project: pip2.7 install virtualenv virtualenv-2.7 my27project # Check the system Python interpreter version: python --version # This will show Python 2.6.6 # Activate the my27project sandbox and check the version of the default Python interpreter in it: source my27project/bin/activate python --version # This will show Python 2.7.X deactivate
基本就是这些了,网上不少教程都说要作软连接,但我感受那样作或多或少会对系统有一些未知的影响。这个方法能尽可能保持系统的完整性,不少自带 Python 程序其实在头部都指定了 #!/usr/bin/python
,因此它们用的实际上是 Python 2.6 ,而不是新安装的 Python 2.7 。python2.7
原文:http://digwtx.duapp.com/54.html函数
参考: http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/this