美文网首页
在已经安装python3的ipython后,再安装python2

在已经安装python3的ipython后,再安装python2

作者: ThomasYoungK | 来源:发表于2018-11-27 22:49 被阅读100次

    IPython是python的一个第三方库,使用PIP工具是很容易安装的,但有时总会出些问题,比如2.7.x版本的不能安装IPython的最新版本,会提示有错误。接下来介绍iPython的安装过程及方法。
    直接使用pip2为python2.7.x安装会报如下错误:

    IPython 6.0+ does not support Python 2.6, 2.7, 3.0, 3.1, or 3.2.
        When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
        Beginning with IPython 6.0, Python 3.3 and above is required.
        
        See IPython `README.rst` file for more information:
        
            https://github.com/ipython/ipython/blob/master/README.rst
    

    安装指定版本【推荐】

    sudo pip2 install ipython==8888 #现指定一个不存在的版本以查看可用版本,发现5版本中有5.8.0(你的可能不一样)
    sudo pip2 install ipython==5.8.0
    

    然后又报six版本不对,且无法确定其版本:

    Cannot uninstall 'six'. It is a distutils installed project 
    and thus we cannot accurately determine which files 
    belong to it which would lead to only a partial uninstall.
    

    用以下方法解决

    sudo pip2 install six --upgrade --ignore-installed six
    

    然后重新安装ipython又报:

    Permission denied
    

    发现是因为苹果账号没有创建目录的权限,查了参考文献[3],切换为root用户,安装ipython成功。

    由于我已经装了ipython的python3版本,因此需要新建一个文件/usr/local/bin/ipython2, 里面这样写:

    #!/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
    
    # -*- coding: utf-8 -*-
    import re
    import sys
    
    from IPython import start_ipython
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
        sys.exit(start_ipython())
    
    

    这样在命令行运行ipython2, 输出

    Python 2.7.10 (default, Aug 17 2018, 17:41:52) 
    Type "copyright", "credits" or "license" for more information.
    
    IPython 5.8.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]: 
    
    

    折腾半天,搞定。

    参考文献:
    [1] iPython的安装及问题解决
    [2] pip "Cannot uninstall 'six'. It is a distutils installed project..." 解决方法
    [3] How to Enable the Root User in macOS

    相关文章

      网友评论

          本文标题:在已经安装python3的ipython后,再安装python2

          本文链接:https://www.haomeiwen.com/subject/aphoqqtx.html