Skip to content

ImportError: No module named shutil_get_terminal_size #9815

Closed

Description

@applar

Update from @Carreau :
Reopening, tagging 5.4 we should vendor shutil_get_terminal_size.


After installing ipython sudo apt-get install ipython-notebook , ipython it appears a error, as follows:

jiangyuping@Lenovo:~$ ipython
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 4, in
from IPython import start_ipython
File "/usr/local/lib/python2.7/dist-packages/IPython/init.py", line 48, in
from .core.application import Application
File "/usr/local/lib/python2.7/dist-packages/IPython/core/application.py", line 25, in
from IPython.core import release, crashhandler
File "/usr/local/lib/python2.7/dist-packages/IPython/core/crashhandler.py", line 28, in
from IPython.core import ultratb
File "/usr/local/lib/python2.7/dist-packages/IPython/core/ultratb.py", line 128, in
from IPython.utils.terminal import get_terminal_size
File "/usr/local/lib/python2.7/dist-packages/IPython/utils/terminal.py", line 22, in
from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
ImportError: No module named shutil_get_terminal_size

Activity

  1. takluyver commented on Jul 28, 2016

    @takluyver
    Member

    You have a newer copy of IPython installed outside apt, and it requires the package backports.shutil_get_terminal_size. Use pip to install that.

  2. added this to the no action milestone on Jul 28, 2016
  3. applar commented on Jul 28, 2016

    @applar
    Author

    @takluyver After pip install ipython, it appears

    jiangyuping@Lenovo:~/ipython$ pip install ipython
    Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/local/lib/python2.7/dist-packages

    then, ipython, it appears

    jiangyuping@Lenovo:~/ipython$ ipython
    Traceback (most recent call last):
    File "/usr/local/bin/ipython", line 4, in
    from IPython import start_ipython
    File "/home/jiangyuping/ipython/IPython/init.py", line 48, in
    from .core.application import Application
    File "/home/jiangyuping/ipython/IPython/core/application.py", line 25, in
    from IPython.core import release, crashhandler
    File "/home/jiangyuping/ipython/IPython/core/crashhandler.py", line 28, in
    from IPython.core import ultratb
    File "/home/jiangyuping/ipython/IPython/core/ultratb.py", line 128, in
    from IPython.utils.terminal import get_terminal_size
    File "/home/jiangyuping/ipython/IPython/utils/terminal.py", line 22, in
    from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
    ImportError: No module named shutil_get_terminal_size

  4. takluyver commented on Jul 28, 2016

    @takluyver
    Member

    I meant:

    pip install backports.shutil_get_terminal_size
    

    However, if it's not bringing that as a dependency of IPython, that probably means you have an old version of pip. To upgrade it:

    pip install --upgrade setuptools pip
    
  5. applar commented on Jul 28, 2016

    @applar
    Author

    Thank you, installed successfully.

  6. AllanDaemon commented on Sep 21, 2016

    @AllanDaemon

    I tried a lot of things. The last one that solved was updating setuptools. I also updated pip and reinstalled ipython, etc.

  7. jnault commented on Oct 16, 2016

    @jnault

    Thanks! This did Not work for me. But it gave me an idea... I did a pip install --upgraded with a whl file of the backports.shutil_get_terminal_size

    Prior to that simply doing a pip install resulted in "requirement already satisfied" etc.
    Now I can run Turi's GraphLab Create :)

  8. oschow commented on Oct 28, 2016

    @oschow

    @jnault I'm having the same problem because I tried to install Turi's GraphLab Create. What exact commands did you use?

  9. jnault commented on Oct 28, 2016

    @jnault

    I don't remember exactly, but I do remember it's pretty easy. My steps:

    1. Google search for that file with the extension .whl and
    2. google search How To Install A Whl File
      hm. ok that looks snarky or something. I'm being sincere and trying to help. But that's literally what I did. Pretty sure the file came from pypi. I'm guessing a whl file could possibly install Anything, so I made sure it came from a reputable source.
      I'm guessing the command was: pip install --upgrade backports.shutil_get_terminal_size.whl
  10. minrk commented on Oct 28, 2016

    @minrk
    Member

    @oschow this should work in general:

    # start by making sure pip, setuptools are up to date:
    pip install --upgrade setuptools pip
    # uninstall if pip thinks you already have it but don't seem to:
    pip uninstall backports.shutil_get_terminal_size
    # install it again with out definitely-up-to-date pip:
    pip install --upgrade backports.shutil_get_terminal_size
    
  11. jnault commented on Oct 28, 2016

    @jnault

    ^ Minrk has better advice.
    Minrk, you wrote "if pip thinks you already have it but don't seem to". So, it's possible that the file was scheduled in the initial python install but then missed? Thus it's listed as present but really isn't?

  12. fredtony commented on Nov 23, 2016

    @fredtony

    I had the same problem when trying to install Graphlab Create. minrk's solution fixed it for me as well.

  13. ifermion commented on Dec 7, 2016

    @ifermion

    @minrk had the working solution for me, just an uninstall followed by an install worked for me.
    Here is what I did.

    uninstall if pip thinks you already have it but don't seem to:

    pip uninstall backports.shutil_get_terminal_size

    install it again with out definitely-up-to-date pip:

    pip install --upgrade backports.shutil_get_terminal_size

  14. bevice commented on Jan 7, 2017

    @bevice

    remove <path-to>/Python/2.7/site-packages/backports/__init__.*

  15. 59 remaining items

  16. Vic020 commented on Apr 26, 2017

    @Vic020

    Hello guys,

    if you guys have try to fix this with

    pip install backports.shutil_get_terminal_size
    

    but it didn't work.

    The best way is that examine your sys path

    import sys
    print sys.path
    

    check each path if there is backports package before the correct path of ipython model and delete it directly.

  17. pde commented on May 16, 2017

    @pde

    I have a very odd version of this bug:

    pde@damoclid:~$ ipython
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line 48, in <module>
        from .core.application import Application
      File "/usr/lib/python2.7/dist-packages/IPython/core/application.py", line 25, in <module>
        from IPython.core import release, crashhandler
      File "/usr/lib/python2.7/dist-packages/IPython/core/crashhandler.py", line 28, in <module>
        from IPython.core import ultratb
      File "/usr/lib/python2.7/dist-packages/IPython/core/ultratb.py", line 128, in <module>
        from IPython.utils.terminal import get_terminal_size
      File "/usr/lib/python2.7/dist-packages/IPython/utils/terminal.py", line 22, in <module>
        from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
    ImportError: No module named shutil_get_terminal_size
    pde@damoclid:~$ python
    Python 2.7.13 (default, Jan 19 2017, 14:48:08) 
    [GCC 6.3.0 20170118] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> import backports.shutil_get_terminal_size
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named shutil_get_terminal_size
    >>> import sys
    >>> print [p for p in sys.path if os.path.exists(p + "/backports")]
    ['/usr/lib/python2.7/dist-packages']
    >>> import backports
    >>> backports.__path__
    ['/usr/local/lib/python2.7/dist-packages/backports']
    >>> os.path.exists("/usr/local/lib/python2.7/dist-packages/backports")
    False
    >>> dir(backports)
    ['__doc__', '__name__', '__path__']
    >>> 
    pde@damoclid:~$ cd /usr/local/bin/
    pde@damoclid:/usr/local/bin$ cd ..
    pde@damoclid:/usr/local$ sudo find . -iname \*backports\*
    pde@damoclid:/usr/local$
    
  18. pde commented on May 16, 2017

    @pde

    I really can't tell why python isn't finding the native OS packaged backports / backports.shutil_get_terminal_size, or why it is finding a ghostly version of backports in /usr/local/lib. My sys.path is:

    ['', '/usr/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/ropevim-0.7.0-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/pde/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-3.0-gtk2']

    pde@damoclid:/usr/local$ ls -ld `dpkg -L python-backports-shutil-get-terminal-size `
    drwxr-xr-x   26 root root   4096 Mar  7 23:01 /./
    drwxr-xr-x   12 root root   4096 Apr  5  2014 /usr/
    drwxr-xr-x  201 root root  36864 May 14 22:01 /usr/lib/
    drwxr-xr-x   27 root root  20480 Apr  4 15:53 /usr/lib/python2.7/
    drwxr-xr-x  296 root root  20480 May 15 18:02 /usr/lib/python2.7/dist-packages/
    drwxr-xr-x    3 root root   4096 May 15 17:35 /usr/lib/python2.7/dist-packages/backports/
    -rw-r--r--    1 root root     75 Aug 19  2014 /usr/lib/python2.7/dist-packages/backports/__init__.py
    drwxr-xr-x    2 root root   4096 May 15 17:35 /usr/lib/python2.7/dist-packages/backports/shutil_get_terminal_size/
    drwxr-xr-x    2 root root   4096 May 15 17:35 /usr/lib/python2.7/dist-packages/backports.shutil_get_terminal_size-1.0.0.egg-info/
    -rw-r--r--    1 root root      1 Jul 28  2016 /usr/lib/python2.7/dist-packages/backports.shutil_get_terminal_size-1.0.0.egg-info/dependency_links.txt
    -rw-r--r--    1 root root   1402 Jul 28  2016 /usr/lib/python2.7/dist-packages/backports.shutil_get_terminal_size-1.0.0.egg-info/PKG-INFO
    -rw-r--r--    1 root root     10 Jul 28  2016 /usr/lib/python2.7/dist-packages/backports.shutil_get_terminal_size-1.0.0.egg-info/top_level.txt
    -rw-r--r--    1 root root   2913 Aug 19  2014 /usr/lib/python2.7/dist-packages/backports/shutil_get_terminal_size/get_terminal_size.py
    -rw-r--r--    1 root root    338 Aug 19  2014 /usr/lib/python2.7/dist-packages/backports/shutil_get_terminal_size/__init__.py
    drwxr-xr-x  398 root root  12288 May 14 22:01 /usr/share/
    drwxr-xr-x 3114 root root 126976 May 15 18:02 /usr/share/doc/
    drwxr-xr-x    2 root root   4096 May 15 17:35 /usr/share/doc/python-backports-shutil-get-terminal-size/
    -rw-r--r--    1 root root    333 Jul 28  2016 /usr/share/doc/python-backports-shutil-get-terminal-size/changelog.Debian.gz
    -rw-r--r--    1 root root     71 Aug 19  2014 /usr/share/doc/python-backports-shutil-get-terminal-size/changelog.gz
    -rw-r--r--    1 root root   1372 Jul 28  2016 /usr/share/doc/python-backports-shutil-get-terminal-size/copyright
    
  19. Carreau commented on May 16, 2017

    @Carreau
    Member

    I'm going to reopen and tag as 5.4 I think we should vendor shutil_get_terminal_size to be safe.

  20. modified the milestones: 5.4, no action on May 16, 2017
  21. pde commented on May 16, 2017

    @pde

    @Carreau fwiw it feels like there might be a pip or python bug here, or I did something foolish, or perhaps both. Will run it past some more knowledgeable pip people.

  22. takluyver commented on May 16, 2017

    @takluyver
    Member

    Another case where it's finding a backports package that isn't really there. A few people have reported something like that, but I can't figure out where it comes from either. Could you have a go at running this script? And look around for .pkg and .pth files, which might be affecting it.

  23. pde commented on May 16, 2017

    @pde

    @Carreau on my system, the problem turned out to be the presence of the configparser module:

    pde@damoclid:~/aip$ sudo grep backport `locate *.pth`
    /usr/local/lib/python2.7/dist-packages/configparser-3.5.0-nspkg.pth:import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('backports',));ie = os.path.exists(os.path.join(p,'__init__.py'));m = not ie and sys.modules.setdefault('backports', types.ModuleType('backports'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
    pde@damoclid:~/aip$ pip freeze | grep configp
    configparser==3.3.0.post2
    pde@damoclid:~/aip$ cd /usr/local/lib/
    pde@damoclid:/usr/local/lib$ find . -iname *configp*
    ./python2.7/dist-packages/configparser-3.5.0.dist-info
    ./python2.7/dist-packages/future/moves/configparser.py
    ./python2.7/dist-packages/future/moves/configparser.pyc
    ./python2.7/dist-packages/configparser.py
    ./python2.7/dist-packages/configparser-3.5.0-nspkg.pth
    ./python2.7/dist-packages/configparser.pyc
    pde@damoclid:/usr/local/lib$ sudo pip uninstall configparser
    Not uninstalling configparser at /usr/lib/python2.7/dist-packages, outside environment /usr
    pde@damoclid:/usr/local/lib$ sudo rm -rf `find . -iname *configp*`
    pde@damoclid:/usr/local/lib$ ipython
    Python 2.7.13 (default, Jan 19 2017, 14:48:08) 
    Type "copyright", "credits" or "license" for more information.
    
    IPython 5.1.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]:                                                                                                                                                                 
    Do you really want to exit ([y]/n)? y
    

    Thanks to @erikrose for help debugging this.

  24. added 2 commits that reference this issue on May 23, 2017
    db7d187
    e50d811
  25. Carreau commented on May 29, 2017

    @Carreau
    Member

    Closing as #10587 vendor this things and IPython 5.4 should be released soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions