CentOS安装python3.6及相应版本的ipython
2018-03-30 本文已影响136人
六月天的安静
默认centos7的python版本是python2.7,并且没有安装ipython
安装python3.6
安装依赖
# yum install xz gcc zlib zlib-devel wget sqlite-devel openssl-devel -y
官网下载源码
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
解压文件
# tar xf Python-3.6.1.tar.xz
进入目录安装编译
# cd Python-3.6.1
# ./configure --prefix=/usr/python3.6
# make && make install
让系统默认使用python3
# cd /usr/bin/
# mv python python.bak
# ln -s /usr/python3.6/bin/python3 /usr/bin/python
设置python3相关变量
# tail -1 /etc/profile
PATH=$PATH:/usr/python3.6/bin/
# . /etc/profile
yum使用的是python2,替换python3之后可能导致无法正常工作,因此需要yum继续使用python2
# head -1 /usr/bin/yum
#!/usr/bin/python2
# head -1 /usr/libexec/urlgrabber-ext-down
#! /usr/bin/python2
进入python3
# python
Python 3.6.1 (default, Mar 23 2018, 16:29:11)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
安装ipython
下载ipython安装包
# wget https://pypi.python.org/packages/79/63/b671fc2bf0051739e87a7478a207bbeb45cfae3c328d38ccdd063d9e0074/ipython-6.1.0.tar.gz
#md5=1e15e1ce3f3f722da6935d7ac0e51346
安装ipython
# tar xf ipython-6.1.0.tar.gz
# cd ipython-6.1.0
# python setup.py install
changing mode of /usr/python3.6/bin/ipython3 to 755
changing mode of /usr/python3.6/bin/iptest3 to 755
running install_data
copying docs/man/ipython.1 -> /usr/python3.6/share/man/man1
running install_egg_info
Writing /usr/python3.6/lib/python3.6/site-packages/ipython-6.1.0-py3.6.egg-info
进入ipython,报错
# ipython
Traceback (most recent call last):
File "/usr/python3.6/bin/ipython", line 4, in <module>
from IPython import start_ipython
File "/usr/python3.6/lib/python3.6/site-packages/IPython/__init__.py", line 54, in <module>
from .core.application import Application
File "/usr/python3.6/lib/python3.6/site-packages/IPython/core/application.py", line 23, in <module>
from traitlets.config.application import Application, catch_config_error
ModuleNotFoundError: No module named 'traitlets'
根据报错提示安装缺失的相关模块
# pip3 install traitlets
# pip3 install pygments
# pip3 install pexpect
# pip3 install pickleshare
# pip3 install prompt_toolkit
# pip3 install simplegeneric
再次尝试进入ipython
#ipython
Python 3.6.1 (default, Dec 23 2017, 19:28:41)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: