CentOS6.8安装python2.7
注:此操作本人用Centos6.8最小化安装通过
为了ipython可以保存历史纪录,还需要安装sqlite-devel
1.准备工作
yum -y install GCc wget xz unzip zlib-devel openssl openssl-devel sqlite-devel
2.下载源码
wget
https://www.Python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
3.解压:
xz -d Python-2.7.12.tar.xz
tar xf Python-2.7.12.tar
cd Python-2.7.12
./configure --prefix=/usr/local/python
make
make install
3.替换系统自带Python
安装后,Python 2.7.8的可执行文件位于/usr/local/python/bin。先将系统自带的Python重命名为python2.6.6,再创建新的Python到/usr/bin目录下的符号链接。
mv /usr/bin/python /usr/bin/python2.6.6
ln -sv /usr/local/python/bin/python2.7 /usr/bin/python
4.修正yum
现在,系统默认调用Python 2.7.12,执行yum会出现错误。
解决方法:将/usr/bin/yum文件开头的第一行代码:
#!/usr/bin/python
改为:
#!/usr/bin/python2.6.6
到此python2.7.12安装完成
接下来安装ipython
ipython安装
1.下载ipython
wget
Https://GitHub.com/ipython/ipython/arcHive/master.zip
2.解压安装
unzip master.zip
cd ipython-master
python setup.py build
python setup.py install
3.创建符号链接
ln -sv /usr/local/python/bin/ipython2 /usr/bin/ipython
4.安装pip
此时如果直接运行ipython的话,会提示下面的错误,这是由于没有安装相应的模块导致的:
No module named traitlets.config.application
wget
https://pypi.python.org/packages/9f/7c/0a33c528164f1b7ff8cf0684cf88c2e733c8ae0119ceca4a3955c7fc059d/setuptools-23.1.0.tar.gz
tar xf setuptools-23.1.0.tar.gz
cd setuptools-23.1.0
python setup.py install
wget
https://pypi.python.org/packages/e7/a8/7556133689add8d1a54c0b14aeff0acb03c64707ce100ecd53934da1aa13/pip-8.1.2.tar.gz
tar xf pip-8.1.2.tar.gz
cd pip-8.1.2
python setup.py install
创建符号链接
ln -sv /usr/local/python/bin/pip2.7 /usr/bin/pip
然后执行ipython看提示缺少什么模块就直接
pip install module_name
pip install traitlets
pip install pygments
pip install pexpect
pip install backports.shutil_get_terminal_size
pip install pathlib2
pip install pickleshare
pip install prompt_toolkit
pip install simplegeneric
好了 ipython环境搭建好了。
相关文章