环境
默认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/profilePATH=$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
# pythonPython 3.6.1 (default, Dec 23 2017, 18:29:11) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> exit()
安装ipython3
下载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 755changing mode of /usr/python3.6/bin/iptest3 to 755running install_datacopying docs/man/ipython.1 -> /usr/python3.6/share/man/man1running install_egg_infoWriting /usr/python3.6/lib/python3.6/site-packages/ipython-6.1.0-py3.6.egg-info
进入ipython,报错
# ipythonTraceback (most recent call last):File "/usr/python3.6/bin/ipython", line 4, in <module>from IPython import start_ipythonFile "/usr/python3.6/lib/python3.6/site-packages/IPython/__init__.py", line 54, in <module>from .core.application import ApplicationFile "/usr/python3.6/lib/python3.6/site-packages/IPython/core/application.py", line 23, in <module>from traitlets.config.application import Application, catch_config_errorModuleNotFoundError: No module named 'traitlets'
根据报错提示安装缺失的相关模块
# pip3 install traitlets # pip3 install pygments# pip3 install pexpect# pip3 install pickleshare# pip3 install prompt_toolkit# pip3 install simplegeneric
再次尝试进入ipython
#ipythonPython 3.6.1 (default, Dec 23 2017, 19:28:41) Type 'copyright', 'credits' or 'license' for more informationIPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.In [1]: