Ipython: ImportError: No module named shutil_get_terminal_size

Created on 28 Jul 2016  ·  81Comments  ·  Source: ipython/ipython

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

Most helpful comment

@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

All 81 comments

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.

@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

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

Thank you, installed successfully.

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

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 :)

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

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

@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 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?

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

@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

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

@bevice And then?

So far I haven't been able to fix with any of the suggestions on this thread or any other thread.

If I run

$ python -s
>>> from backports.shutil_get_terminal_size import get_terminal_size
>>> get_terminal_size()
terminal_size(columns=112, lines=40)

it works. But running ipython or jupyter notebook gives me the same error, that it doesn't find shutil_get_terminal_size

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.

@takluyver Thanks for the quick reply.

This is what I found:

backports-abc (0.4)
backports.shutil-get-terminal-size (1.0.0)
backports.ssl-match-hostname (3.4.0.2)

What can I do now?

Uninstall backports.ssl-match-hostname and backports.shutil-get-terminal-size and install them again.

Do I have to "restart" anaconda or something for the changes to take effect? Uninstalling both the packages you mentioned and reinstalling them didn't work.

No, there's no restart. Just to make sure, though, after you uninstall them, try uninstalling again. Repeat until it can't find anything to uninstall. Sometimes there are copies in different places.

If that's still not working, try uninstalling backports.ssl-match-hostname and leaving it uninstalled (at least until you find what needs it...)

Alright. I tried everything you said, yet nothing works. What are my options? The problem started when I installed pymc3. The other thing is, I changed some scripts in order to add some modules to the nipype toolbox. Should I just remove everything and install it again? This would be the last resort, I hope.

What do you get trying this in the same Python you're trying to run IPython with:

import backports
print(backports)

I've run it with backports installed:

>>> import backports
>>> print(backports)
<module 'backports' from '/nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports/

Then uninstalled them, and ran it again:

>>> import backports
>>> print(backports)
<module 'backports' (built-in)>

So apparently I have some built in packages somewhere that are screwing things up. But I have no idea how to find them. Even if I find them I might not be able to change anything as I have no root permissions.

Is there anything else in the folder that it showed you there (/nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports/)?

Nope, now that it is uninstalled the folder is missing completely. As is the folder
../site-packages/backports.shutil-get-terminal-size-1.0.0 which used to be there when it was installed.

Can you check backports.__path__ in Python?

Without backports installed:
['/nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports']

That's the same directory as before? Is it definitely missing? I don't understand how it could find that path if there's nothing there.

I searched for all possible backports in the anaconda2_serverwide directory. I'm not sure what this all means.
This is what I found:

file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/future-0.15.2-py27_0/lib/python2.7/site-packages/future/backports
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/configparser-3.5.0-py27_0/lib/python2.7/site-packages/backports
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/ssl_match_hostname-3.4.0.2-py27_1/lib/python2.7/site-packages/backports
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/get_terminal_size-1.0.0-py27_0/lib/python2.7/site-packages/backports
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/future/backports
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports.shutil_get_terminal_size-1.0.0-py27_1/lib/python2.7/site-packages/backports
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports-1.0-py27_0/lib/python2.7/site-packages/backports
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports-1.0-py27_0
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports_abc-0.4-py27_0
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports_bak
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports.shutil_get_terminal_size-1.0.0-py27_1/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports.shutil_get_terminal_size-1.0.0-py27_1
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/get_terminal_size-1.0.0-py27_0/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0-py2.7.egg-info
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/ssl_match_hostname-3.4.0.2-py27_1/lib/python2.7/site-packages/backports.ssl_match_hostname-3.4.0.2-py2.7.egg-info
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports-1.0-py27_0.tar.bz2
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports.shutil_get_terminal_size-1.0.0-py27_1.tar.bz2
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports_abc-0.4-py27_0/lib/python2.7/site-packages/backports_abc-0.4-py2.7.egg-info
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports_abc-0.4-py2.7.egg-info
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/conda-meta/backports-1.0-py27_0.json
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/conda-meta/backports_abc-0.4-py27_0.json
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/conda-meta/backports.shutil_get_terminal_size-1.0.0-py27_1.json
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports_abc.py
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports_abc-0.4-py27_0/lib/python2.7/site-packages/backports_abc.py
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports_abc.pyc
file:///nobackup/archimedes1/Glad/anaconda2_serverwide/pkgs/backports_abc-0.4-py27_0/lib/python2.7/site-packages/backports_abc.pyc

Had you restarted Python after uninstalling backports? If not, can you restart Python and check backports.__path__ again? I don't know of any way it could identify that path if there's no file there.

How do I restart python?

I've also tried the following:

> conda list | grep backports
backports                 1.0                      py27_0  
backports.shutil_get_terminal_size 1.0.0                    py27_1    conda-forge
backports_abc             0.4                      py27_0  

So I used conda to remove backports.shutil_get_terminal_size:
> conda uninstall backports.shutil_get_terminal_size

When I now try to import backports.shutil_get_terminal_size in python it doesn't find it. So I removed ipython and jupyter and re-installed ipython through conda which also installed jupyter and backports.shutil_get_terminal_size. However, it _still_ doesn't work! I'm stumped.

I then removed the installations through conda and re-installed them through pip. It _still_ doesn't work....

How do I restart python?

Close it (exit()) and then start it again.

Checked for backports:

> conda list | grep backports
backports                 1.0                      py27_0  
backports.shutil_get_terminal_size 1.0.0                    py27_1    conda-forge
backports_abc             0.4                      py27_0  

Ran python after restarting it:

>>> import backports
>>> backports.shutil_get_terminal_size
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'shutil_get_terminal_size'

Tried to upgrade it:

> pip install --upgrade backports.shutil_get_terminal_size
Requirement already up-to-date: backports.shutil_get_terminal_size in /nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages

I don't get it. What else can I do? Can I edit ´terminal.py´ to point it in the right direction?

If you uninstall all backports packages, restart Python and check:

import backports
backports.__path__

What do you get?

>>> import backports
>>> backports.__path__
['/home/raid2/mihai/.local/lib/python2.7/site-packages/backports', '/nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports']

Is there anything installed in the former directory (the one under /home/raid2)?

That's the directory where the systemwide python and ipython packages are stored. I'm not using them, however, as I am using the local anaconda install. And it shouldn't interfere. Truth be told, under the /home/raid2... directorey there is no backports.shutil_get_terminal_size package.

When I run the systemwide install (which has an older version of ipython) it runs just fine. But when I start my environment with the newer anaconda install with
export PATH="/nobackup/archimedes1/Glad/anaconda2_serverwide/bin:$PATH", it fails to find the window size function.

I've made a script to try to help debugging this. Can you run it and post the output?

https://gist.github.com/takluyver/73cf4e7e7cff4d95f3b23ea80d59bcab

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 !

Here's the output of your script:

In [2]: run debug_namespace_pkg.py
mod: <module 'backports' from '/home/raid2/mihai/.local/lib/python2.7/site-packages/backports/__init__.pyc'>

backports.__path__ = ['/home/raid2/mihai/.local/lib/python2.7/site-packages/backports', '//nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports']

Found /home/raid2/mihai/.local/lib/python2.7/site-packages/backports
__init__.py contains:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)


Found //nobackup/archimedes1/Glad/anaconda2_serverwide/lib/python2.7/site-packages/backports
__init__.py contains:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

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.

I also have the same problem. Tried everything from the start, uninstalling and installing everything. Also ran the script you shared above -
Here's the output:

aranyo-139-61:Desktop shiva$ python debug_namespace_pkg.py
mod: <module 'backports' (built-in)>

backports.__path__ = ['/Users/shiva/Library/Python/2.7/lib/python/site-packages/backports']

Found /usr/local/lib/python2.7/site-packages/backports
__init__.py contains:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)


Found /Users/shiva/Library/Python/2.7/lib/python/site-packages/backports
No __init__.py found
Found /usr/local/lib/python2.7/site-packages/backports
__init__.py contains:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

Can you help me with this? I don't want to use conda though.

Thanks!

Is there anything in /Users/shiva/Library/Python/2.7/lib/python/site-packages/backports? Can you try removing/renaming it?

Is there anything in /Users/shiva/Library/Python/2.7/lib/python/site-packages/backports? Can you try removing/renaming it?

Tried, Still the same problem.

I made a change to the debugging script, can you try getting it again and re-running it.

Here's the output -

mod: <module 'backports' (built-in)>

backports.__path__ = ['/Users/shiva/Library/Python/2.7/lib/python/site-packages/backports']

-- Found /usr/local/lib/python2.7/site-packages/backports --
Files: ['__init__.py', '__init__.pyc', 'shutil_get_terminal_size']
__init__.py contains:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)


-- Found /usr/local/lib/python2.7/site-packages/backports --
Files: ['__init__.py', '__init__.pyc', 'shutil_get_terminal_size']
__init__.py contains:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

Have you restarted Python since removing/renaming that directory? It's still finding it somehow.

I am running the script using "python debug_namespace_pkg.py" command. And I restarted the terminal before doing it.

And /Users/shiva/Library/Python/2.7/lib/python/site-packages/backports definitely doesn't exist? As before, I don't understand how it's getting a reference to a folder that apparently isn't there.

Yes I renamed it in the location you specified. Are you sure you do not mean /usr/local/lib/python2.7/site-packages/backports ?

No, that's the one it needs to find. The one under /Users/shiva seems to be getting in the way of it somehow. This line shows that it's still finding it somehow:

backports.__path__ = ['/Users/shiva/Library/Python/2.7/lib/python/site-packages/backports']

But I don't understand how that's possible after you've removed it. :confused:

Aha, there's something I never knew about: .pkg files. Can you look for a file called backports.pkg?

(backports.pkg will probably be in one of those site-packages directories, though it might be somewhere else on your system)

I can't find backports.pkg anywhere. I used find ./* -name backports.pkg in the root folder.

Finally, it worked.

Renaming that folder doesn't work, removing it does. Thanks a lot for your help :)

Weird, I don't understand why removing it would be different from just renaming it. Glad you got it working, anyway.

I am having similar problems and pip uninstalling/installing stuff does not seem to be helping. This is the output of your debugging script (due to python test.py):

mod: <module 'backports' (built-in)>

backports.__path__ = ['/home/ihincks/.local/lib/python2.7/site-packages/backports']

-- Found /usr/local/lib/python2.7/dist-packages/backports --
Files: ['__init__.py', '__init__.pyc', 'shutil_get_terminal_size']
__init__.py contains:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

I have:

$ ls /home/ihincks/.local/lib/python2.7/site-packages/ | grep backports
backports_abc-0.5.dist-info
backports_abc.py
backports_abc.pyc
backports.shutil_get_terminal_size-1.0.0

I eventually got it working by the following hack method. Open up (on linux) /usr/local/lib/python2.7/dist-packages/IPython/utils/terminal.py and change the line

from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size

to

from shutil_backports import get_terminal_size as _get_terminal_size

Same thing again - somehow it's finding a directory that doesn't seem to be there. Can you look for a backport.pkg file as well? I'll add that to the script.

Output from lastest script:

mod: <module 'backports' (built-in)>

backports.__path__ = ['/home/ihincks/.local/lib/python2.7/site-packages/backports']

-- Found /usr/local/lib/python2.7/dist-packages/backports --
Files: ['__init__.py', '__init__.pyc', 'shutil_get_terminal_size']
__init__.py contains:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

That's infuriating; I can't figure out how it's finding the first path (/home/ihincks/...).

Is there anything else in /home/ihincks/.local/lib/python2.7/site-packages/ that might explain why it's finding backports there?

I don't know exactly what to be looking for. Here is everything in /home/ihincks/.local/lib/python2.7/site-packages/:

backports_abc-0.5.dist-info
backports_abc.py
backports_abc.pyc
backports.shutil_get_terminal_size-1.0.0
bleach
bleach-1.5.0.dist-info
certifi
certifi-2016.9.26.dist-info
configparser-3.5.0.dist-info
configparser-3.5.0-nspkg.pth
configparser.py
configparser.pyc
entrypoints-0.2.2.dist-info
entrypoints.py
entrypoints.pyc
enum
enum34-1.1.6.dist-info
functools32
functools32-3.2.3.post2.dist-info
html5lib
html5lib-0.9999999.dist-info
ipykernel
ipykernel-4.5.2.dist-info
ipython_genutils
ipython_genutils-0.1.0.dist-info
ipywidgets
ipywidgets-5.2.2.dist-info
jinja2
Jinja2-2.8.dist-info
jsonschema
jsonschema-2.5.1.dist-info
jupyter_client
jupyter_client-4.4.0.dist-info
jupyter_console
jupyter_console-5.0.0.dist-info
jupyter_core
jupyter_core-4.2.1.dist-info
markupsafe
MarkupSafe-0.23.dist-info
mistune-0.7.3.dist-info
mistune.py
mistune.pyc
nbconvert
nbconvert-5.0.0.dist-info
nbformat
nbformat-4.2.0.dist-info
pandocfilters-1.4.1.dist-info
pandocfilters.py
pandocfilters.pyc
pexpect
pexpect-4.2.1.dist-info
pickleshare-0.7.4.dist-info
pickleshare.py
pickleshare.pyc
prompt_toolkit
prompt_toolkit-1.0.9.dist-info
ptyprocess
ptyprocess-0.5.1.dist-info
pyzmq-16.0.2.dist-info
qtconsole
qtconsole-4.2.1.dist-info
simplegeneric-0.8.1.dist-info
simplegeneric.py
simplegeneric.pyc
singledispatch-3.4.0.3.dist-info
singledispatch_helpers.py
singledispatch_helpers.pyc
singledispatch.py
singledispatch.pyc
six-1.10.0.dist-info
six.py
six.pyc
terminado
terminado-0.6.dist-info
testpath
testpath-0.3.dist-info
tornado
tornado-4.4.2.dist-info
traitlets
traitlets-4.3.1.dist-info
wcwidth
wcwidth-0.1.7.dist-info
widgetsnbextension
widgetsnbextension-1.2.6.dist-info
zmq

What is backports.shutil_get_terminal_size-1.0.0 and what's inside it?

It is a python package, which seems to expose the single function get_terminal_size in backports.shutil_get_terminal_size. This folder has structure:

./
├── backports
│   ├── __init__.py
│   └── shutil_get_terminal_size
│       ├── get_terminal_size.py
│       └── __init__.py
├── backports.shutil_get_terminal_size.egg-info
│   ├── dependency_links.txt
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   └── top_level.txt
├── HISTORY.rst
├── LICENSE
├── MANIFEST.in
├── PKG-INFO
├── README.rst
├── setup.cfg
├── setup.py
├── test_shutil_get_terminal_size.py
└── tox.ini

The contents of PKG-INFO are:

Metadata-Version: 1.1
Name: backports.shutil_get_terminal_size
Version: 1.0.0
Summary: A backport of the get_terminal_size function from Python 3.3's shutil.
Home-page: https://github.com/chrippa/backports.shutil_get_terminal_size
Author: Christopher Rosell
Author-email: [email protected]
License: MIT
Description: backports.shutil_get_terminal_size
        ==================================

        A backport of the `get_terminal_size`_ function from Python 3.3's shutil.

        Unlike the original version it is written in pure Python rather than C,
        so it might be a tiny bit slower.

        .. _get_terminal_size: https://docs.python.org/3/library/shutil.html#shutil.get_terminal_size


        Example usage
        -------------

            >>> from backports.shutil_get_terminal_size import get_terminal_size
            >>> get_terminal_size()
            terminal_size(columns=105, lines=33)



        History
        =======

        1.0.0 (2014-08-19)
        ------------------

        First release.

Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2

Ah, OK, I'm guessing you unpacked the sdist there manually at some point. Does deleting that whole directory (backports.shutil_get_terminal_size-1.0.0) make any difference? I'm guessing that it's just a red herring.

Okay, reverted /usr/local/lib/python2.7/dist-packages/IPython/utils/terminal.py back to original form. Ran ipython and got ImportError: No module named shutil_get_terminal_size error.

Then moved folder /home/ihincks/.local/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0 to /home/ihincks temporarily. Ran ipython again, with the same error.

OK, so that folder is just a red herring, and I'm still in the dark about how it is finding /home/ihincks/.local/lib/python2.7/site-packages/backports :-(

Hmm, wish I could be of more help, I only half understand what is going on; python path/library installation stuff generally confuses me.

No problem, this seems to be some fairly well hidden black magic.

If anyone can replicate this on a system where they don't mind giving me ssh access to poke around and try to understand what's going on, please get in touch.

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

So I encountered this problem, and upon inspecting /usr/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info, I found only:

total 28
-rw-r--r--. 1 root root  596 Feb 27 10:42 DESCRIPTION.rst
-rw-r--r--. 1 root root    4 Feb 27 10:42 INSTALLER
-rw-r--r--. 1 root root 1175 Feb 27 10:42 METADATA
-rw-r--r--. 1 root root  701 Feb 27 10:42 metadata.json
-rw-r--r--. 1 root root 1455 Feb 27 10:42 RECORD
-rw-r--r--. 1 root root   10 Feb 27 10:42 top_level.txt
-rw-r--r--. 1 root root  110 Feb 27 10:42 WHEEL

and nothing to import. This after pip --upgrade, pip uninstall/install ipython and so on. So it looks like pip was not actually installing the package, just the wheel. I downloaded the .tar.gz file, copied it over the wheel directory which fixed it issue I had with ipython. Not the right way to fix it tho. I am running in RHEL7, so that probably has something to do with it.

The directory that ends in .dist-info is a metadata file about the installed package, it's not meant to contain anything importable. The code should be in an adjacent directory: /usr/lib/python2.7/site-packages/backports

Maybe the code can help you : pip install --user backports.shutil_get_terminal_size ,just install it for current user if your ipython is ok for root or other users.

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 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$

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

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

@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.

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.

@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.

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

Was this page helpful?
0 / 5 - 0 ratings