}

No module named shutil_get_terminal_size

Created:

While using Jupyter I got the following stack trace when calling ipykernel:

  File "<path to python>/lib/python2.7/site-packages/ipykernel-4.3.1-py2.7.egg/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "<path to python>/lib/python2.7/site-packages/ipykernel-4.3.1-py2.7.egg/ipykernel/connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "<path to python>/lib/python2.7/site-packages/ipython-5.0.0b4-py2.7.egg/IPython/__init__.py", line 48, in <module>
    from .core.application import Application
  File "<path to python>/lib/python2.7/site-packages/ipython-5.0.0b4-py2.7.egg/IPython/core/application.py", line 24, in <module>
    from IPython.core import release, crashhandler
  File "<path to python>/lib/python2.7/site-packages/ipython-5.0.0b4-py2.7.egg/IPython/core/crashhandler.py", line 28, in <module>
    from IPython.core import ultratb
  File "<path to python>/lib/python2.7/site-packages/ipython-5.0.0b4-py2.7.egg/IPython/core/ultratb.py", line 126, in <module>
    from IPython.utils.terminal import get_terminal_size
  File "<path to python>/lib/python2.7/site-packages/ipython-5.0.0b4-py2.7.egg/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

THe error was thrown with OSX and Python 2.7.10.

Solution 1

This probably means that you have a too-old version of setuptools or you might be using easy_install. First things first,

Make sure you have relatively recent pip/setuptools, upgrade pip and setuptools with:

pip install --upgrade setuptools pip

Reinstalling IPython with pip:

pip uninstall ipython
pip install ipython

Solution 2

It seems that ipython 4.2 causes some problems, using 4.2 with the error can be reproduced. If you switch ipython to 4.1.1 the error can't be reproduced.

You can try to switch back to 4.1.1

pip install --user --upgrade ipython==4.1.1

Note that with --user the command line python tool is installed at ~/Library/Python/2.7/bin/ipython instead of /usr/local/bin on OSX.

Solution 3

Another solution is to uninstall and install backports.shutil_get_terminal_size again.

pip uninstall backports.shutil_get_terminal_size
Uninstalling backports.shutil-get-terminal-size-1.0.0:
  /home/pierre/Programmes/anaconda/lib/python2.7/site-packages/backports
  /home/pierre/Programmes/anaconda/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0-py2.7.egg-info
Proceed (y/n)? y
  Successfully uninstalled backports.shutil-get-terminal-size-1.0.0
pip install backports.shutil_get_terminal_size
Collecting backports.shutil_get_terminal_size
  Downloading backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
Installing collected packages: backports.shutil-get-terminal-size
Successfully installed backports.shutil-get-terminal-size-1.0.0