ipython: ImportError: No module named shutil_get_terminal_size

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 <module> from IPython import start_ipython File “/usr/local/lib/python2.7/dist-packages/IPython/init.py”, line 48, in <module> from .core.application import Application File “/usr/local/lib/python2.7/dist-packages/IPython/core/application.py”, line 25, in <module> from IPython.core import release, crashhandler File “/usr/local/lib/python2.7/dist-packages/IPython/core/crashhandler.py”, line 28, in <module> from IPython.core import ultratb File “/usr/local/lib/python2.7/dist-packages/IPython/core/ultratb.py”, line 128, in <module> from IPython.utils.terminal import get_terminal_size File “/usr/local/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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 81 (34 by maintainers)

Commits related to this issue

Most upvoted comments

@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

@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

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

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.

I too got the same problem…I installed jupyter recently and when i tried to open a ipython notebook file it says the kernel is dead with an import error for backports.shutil_get_terminal_size. Finally, I solved this problem after upgrading pip, re-installing jupyter and backports.shutil-get-terminal-size several times…and finally running this command : python2 -m ipykernel install --user. That gave life to my kernel. Ref : http://askubuntu.com/questions/847263/install-jupyter-for-python-2-7-in-ubuntu-14-04

OK, glad you got it working. The output from the script now shows things as they’re supposed to be; hopefully the script might be useful if someone has this problem in future.

Alright!!!1

This is what I did to somehow make it work. Uninstalled ipython and jupyter and backports.shutil_get_window_size with both conda and pip:

conda uninstall jupyter ipython backports.shutil_get_window_size
pip uninstall jupyter ipython backports.shutil_get_window_size

I made sure there is nothing left of any package. Then I reinstalled only ipython with conda:

> conda install ipython
Fetching package metadata .........
Solving package specifications: ..........

Package plan for installation in environment //nobackup/archimedes1/Glad/anaconda2_serverwide:

The following NEW packages will be INSTALLED:

    backports:                          1.0-py27_0              
    backports.shutil_get_terminal_size: 1.0.0-py27_1 conda-forge
    ipython:                            5.1.0-py27_1 conda-forge

Proceed ([y]/n)? y

Extracting packages ...
[      COMPLETE      ]|###################################################################################| 100%
Linking packages ...
[      COMPLETE      ]|###################################################################################| 100%
mihai@archimedes:/tmp > ipython

And now it works!!! Thanks for your generous time @takluyver !

I think this means you have another backports.<something> package installed somewhere that has messed up the namespace package machinery. You’ll probably need to find that and uninstall it. Try pip list to see all installed packages.

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

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