Linux 系统安装 ipython 时遇到的报错

背景:

记录一下本人在Linux系统上安装 ipython 时遇到的情况。
  我的环境:CentOS6.8,Python2.7.13,pip-19.0.3,setuptools-40.8.0,之前的文章提到过CentOS6.8默认带的python为2.6,现在给升了Python2.7。

过程:

pip install ipython 命令安装时的报错:
(py27) [root@VM_0_15_centos venvs]# pip install ipython
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Collecting ipython
  Downloading http://mirrors.tencentyun.com/pypi/packages/e3/88/39c8b7701b2f7d5c8f3a1796b0c174f21071232bc5b242feb670e913acc6/ipython-7.4.0.tar.gz (5.1MB)
    100% |????????????????????????????????| 5.1MB 71.4MB/s 
    Complete output from command python setup.py egg_info:
    
    IPython 7.0+ supports Python 3.5 and above.
    When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
    Python 3.3 and 3.4 were supported up to IPython 6.x.
        
    See IPython `README.rst` file for more information:    
        https://github.com/ipython/ipython/blob/master/README.rst  
    Python sys.version_info(major=2, minor=7, micro=13, releaselevel='final', serial=0) detected.
      
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-tr5Lsq/ipython/

于是上网查了下,找到这个 pip安装出现Command “python setup.py egg_info” failed with error code 1 的解决方案 ,这里提到的解决方案是更新 pip和setuptools的版本。但我的环境这两个已经是目前最新的了,如下:

[root@VM_0_15_centos lib]# pip list
Package                            Version
---------------------------------- ------- 
pip                                19.0.3 
setuptools                         40.8.0 

easy_install ipython 安装时报错:

[root@VM_0_15_centos chen]# easy_install ipython
Searching for ipython
Reading http://mirrors.tencentyun.com/pypi/simple/ipython/
Downloading http://mirrors.tencentyun.com/pypi/packages/e3/88/39c8b7701b2f7d5c8f3a1796b0c174f21071232bc5b242feb670e913acc6/ipython-7.4.0.tar.gz#md5=826178c87b7b96651ce8b26a779e3016
Best match: ipython 7.4.0
Processing ipython-7.4.0.tar.gz
Writing /tmp/easy_install-T3OSkd/ipython-7.4.0/setup.cfg
Running ipython-7.4.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-T3OSkd/ipython-7.4.0/egg-dist-tmp-oQ_xS0

IPython 7.0+ supports Python 3.5 and above.
When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
Python 3.3 and 3.4 were supported up to IPython 6.x.

See IPython `README.rst` file for more information:
    https://github.com/ipython/ipython/blob/master/README.rst
Python sys.version_info(major=2, minor=7, micro=13, releaselevel='final', serial=0) detected.

error: Setup script exited with 1

yum install python-ipython.noarch 即用系统的软件包管理器进行安装:

参照 linux centos ubentu安装IPython四种方法 方法三,安装如下:

[root@VM_0_15_centos chen]# yum install python-ipython.noarch
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package python-ipython.noarch 0:0.13.2-7.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================
 Package                Arch            Version                  Repository                Size
========================================================================================================
Installing:
 python-ipython         noarch          0.13.2-7.el6             epel                      11 k

很顺利的安装完了(安装过程中可能会自动安装一些依赖包),接着运行 ipython 又有新的报错:

[root@VM_0_15_centos chen]# ipython 
Traceback (most recent call last):
  File "/usr/bin/ipython", line 5, in <module>
    from IPython.frontend.terminal.ipapp import launch_new_instance
ImportError: No module named IPython.frontend.terminal.ipapp

额,这就难受了。网上查这个报错的 解决方案 。

[root@VM_0_15_centos chen]# vi /usr/bin/ipython
#编辑内容如下:
#!/usr/bin/python
"""Terminal-based IPython entry point.
"""
import sys
if "/usr/lib/python2.6/site-packages" not in sys.path:
    sys.path.append("/usr/lib/python2.6/site-packages")

from IPython.frontend.terminal.ipapp import launch_new_instance
launch_new_instance()

再运行 ipython 成功了!!!

[root@VM_0_15_centos lib]# ipython
WARNING: Readline services not available or not loaded.WARNING: The auto-indent feature requires the readline libraryPython 2.7.13 (default, Mar 29 2019, 12:18:25) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 

等等~,ipython 版本 0.13.2 ,R U kidding me ??? 这版本太低了吧。其实前边执行 yum install python-ipython.noarch 时的输出信息就已经告诉了安装的 ipython 版本信息。为什么会这样呢? 仔细回想了下,之前在升级 Python2.6 到 Python2.7 时,曾修改过yum的配置文件 /usr/bin/yum 把yum的python编译环境改为了系统自带的python版本2.6(yum 安装工具只支持系统自带的python版本),而yum源自带的ipython包就是这么老。

查找问题解决方案过程中,看到了一些类似的问题这里贴下链接,供参考:

  • ImportError: No module named IPython
  • IPython console can’t locate “backports.shutil_get_terminal_size” and won’t load
  • IPython import failure and python sys.path in general

好吧,接下来换个方法吧…

尝试着进行源码安装:

ipython的源码下载页面为:https://pypi.org/project/ipython/#history
进去之后,发现 ipython 那么多版本呀,python2.7.13要安装哪个呢?选择恐惧症犯病了。。。等等。。。之前我用 pip install ipythoneasy_install ipython 命令安装的时候,看到了以下几行信息:

IPython 7.0+ supports Python 3.5 and above.
When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
Python 3.3 and 3.4 were supported up to IPython 6.x.

额,原来 Python2.7 需要安装对应的 ipython5.x 系列的,那就来个ipython5.7的吧。
选完版本后,在 https://pypi.org/project/ipython/5.7.0/ 页面惊奇地发现 页面左上角清清楚楚给了命令 pip install ipython==5.7.0
直接粘贴执行:

[root@VM_0_15_centos ~]# pip install ipython==5.7.0
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Collecting ipython==5.7.0
  Downloading http://mirrors.tencentyun.com/pypi/packages/52/19/aadde98d6bde1667d0bf431fb2d22451f880aaa373e0a241c7e7cb5815a0/ipython-5.7.0-py2-none-any.whl (760kB)
    100% |████████████████████████████████| 768kB 8.5MB/s 
Requirement already satisfied: simplegeneric>0.8 in /chen/mysoft/python/lib/python2.7/site-packages (from ipython==5.7.0) (0.8.1)
...
Installing collected packages: ipython
  The scripts iptest, iptest2, ipython and ipython2 are installed in '/chen/mysoft/python/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed ipython-5.7.0

哇呜,安装成功了,运行一下:

[root@VM_0_15_centos ~]# ipython
/chen/mysoft/python/lib/python2.7/site-packages/IPython/frontend.py:21: ShimWarning: The top-level `frontend` package has been deprecated since IPython 1.0. All its subpackages have been moved to the top `IPython` level.
  "All its subpackages have been moved to the top `IPython` level.", ShimWarning)
Python 2.7.13 (default, Mar 29 2019, 12:18:25) 
Type "copyright", "credits" or "license" for more information.

IPython 5.7.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 

嘿嘿,也成功了,不过有个 Warning 信息,看着不爽??? 点我看看怎么解决吧


再试试 easy_install ipython 命令(虚拟环境下):

(myenv) [root@VM_0_15_centos venvs]# easy_install ipython==5.6.0
Searching for ipython==5.6.0
Reading http://mirrors.tencentyun.com/pypi/simple/ipython/
Downloading http://mirrors.tencentyun.com/pypi/packages/16/af/fbc5ecbb283344365ac98079524f8d61fd1b2afcef31d469023cba80b439/ipython-5.6.0-py2-none-any.whl#md5=e208f5df634ca557501f8d41fdb3838f
Best match: ipython 5.6.0
Processing ipython-5.6.0-py2-none-any.whl
Installing ipython-5.6.0-py2-none-any.whl to /chen/venvs/myenv/lib/python2.7/site-packages
writing requirements to /chen/venvs/myenv/lib/python2.7/site-packages/ipython-5.6.0-py2.7.egg/EGG-INFO/requires.txt
Adding ipython 5.6.0 to easy-install.pth file
Installing ipython script to /chen/venvs/myenv/bin
Installing iptest2 script to /chen/venvs/myenv/bin
Installing iptest script to /chen/venvs/myenv/bin
Installing ipython2 script to /chen/venvs/myenv/bin

Installed /chen/venvs/myenv/lib/python2.7/site-packages/ipython-5.6.0-py2.7.egg
Processing dependencies for ipython==5.6.0
... #一堆依赖包在进行下载安装
Finished processing dependencies for ipython==5.6.0

运行 ipython 看看:

(myenv) [root@VM_0_15_centos venvs]# ipython
Python 2.7.13 (default, Mar 29 2019, 12:18:25) 
Type "copyright", "credits" or "license" for more information.

IPython 5.6.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:  

你是不是发现,这一节我本来是要进行源码安装 ipython 的,结果还是再说 pip 和 easy_install 安装。是的,我最开始用这两个命令的时候,不知道可以指定 ipython 版本号进行安装。导致后边走了好多弯路,又徒增了几根白发,哎~
累了,不想搞了,想看源码安装的,请移步其他人的博客。

  • linux下ipython的安装
  • Centos下安装Ipython

你可能感兴趣的:(Python,ipython安装报错,pip,install,ipython报错,Linux,安装,ipython,yum安装,ipython)