Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named shutil_get_terminal_size #9656

Closed
ajmazurie opened this issue Jun 23, 2016 · 71 comments
Closed

No module named shutil_get_terminal_size #9656

ajmazurie opened this issue Jun 23, 2016 · 71 comments
Milestone

Comments

@ajmazurie
Copy link

Good day,
I am contributing to a small project to create a kernel on top of ipykernel. It has been a while since I touched it, and today when I deployed a new dev environment by installing 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

Obviously something changed since my last use of IPython and ipykernel. Any idea what the problem is? I'm working on a OSX box with Python 2.7.10.

Best, Aurélien

@minrk
Copy link
Member

minrk commented Jun 24, 2016

Looks like you've installed IPython without getting its dependencies somehow. Given that I see eggs, this probably means that you have a too-old version of setuptools, and might be using easy_install. First things first, make sure you have relatively recent pip/setuptools:

pip install --upgrade setuptools pip

Then, try reinstalling IPython with pip (do not ever use easy_install, unless you know that there is a good reason why pip won't/can't work. These cases are rare):

pip uninstall ipython
pip install ipython

@takluyver
Copy link
Member

Specifically in this case, we have added a dependency on the package backports.shutil_get_terminal_size.

@ajmazurie
Copy link
Author

Thanks for your quick feedback! However, the mystery deepens. It looks like installing Jupyter through pip on the command line yields a different result than having Jupyter set as a requirement when using setuptools. While the first approach succeeds, the second approach fails for me. Here are the steps to reproduce this issue:

First we start with a barebone Python 2.7.11 interpreter, with only three packages installed:

$ pip list
pip (8.1.2)
setuptools (23.1.0)
virtualenv (15.0.2)

If I install Jupyter using pip everything works fine, and I get the following packages:

$ pip install jupyter
<long output>
$ pip list
appnope (0.1.0)
backports-abc (0.4)
backports.shutil-get-terminal-size (1.0.0)
backports.ssl-match-hostname (3.5.0.1)
certifi (2016.2.28)
configparser (3.5.0)
decorator (4.0.10)
entrypoints (0.2.2)
functools32 (3.2.3.post2)
gnureadline (6.3.3)
ipykernel (4.3.1)
ipython (4.2.0)
ipython-genutils (0.1.0)
ipywidgets (5.1.5)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter (1.0.0)
jupyter-client (4.3.0)
jupyter-console (4.1.1)
jupyter-core (4.1.0)
MarkupSafe (0.23)
mistune (0.7.2)
nbconvert (4.2.0)
nbformat (4.0.1)
notebook (4.2.1)
pathlib2 (2.1.0)
pexpect (4.1.0)
pickleshare (0.7.2)
pip (8.1.2)
ptyprocess (0.5.1)
Pygments (2.1.3)
pyzmq (15.2.0)
qtconsole (4.2.1)
setuptools (23.1.0)
simplegeneric (0.8.1)
singledispatch (3.4.0.3)
six (1.10.0)
terminado (0.6)
tornado (4.3)
traitlets (4.2.1)
wheel (0.29.0)
widgetsnbextension (1.2.3)

However, if I try to install Jupyter as a requirement for a project by having the following setup.py script (note that I restart from a fresh 2.7.11 interpreter with the three base modules pip, setuptools and virtualenv):

#!/usr/bin/env python
import setuptools
setuptools.setup(
    ...
    install_requires = [
        "jupyter"],
   ...

... then it fails:

$ pip list
pip (8.1.2)
setuptools (23.1.0)
virtualenv (15.0.2)
$ ./setup.py install
<long output>
Searching for entrypoints
Reading https://pypi.python.org/simple/entrypoints/
No local packages or download links found for entrypoints
error: Could not find suitable distribution for Requirement.parse('entrypoints')
make: *** [install] Error 1

Interestingly, when listing the packages that did get installed we can see that ipython and jupyter-console are now version 5.0.0b4 and 5.0.0b1, respectively instead of 4.2.0 and 4.1.1 as above when installing Jupyter with pip. Here are the packages:

$ pip list
ipykernel (4.3.1)
ipython (5.0.0b4)
ipywidgets (5.1.5)
jupyter (1.0.0)
jupyter-client (4.3.0)
jupyter-console (5.0.0b1)
nbconvert (4.2.0)
notebook (4.2.1)
pip (8.1.2)
qtconsole (4.2.1)
setuptools (23.1.0)
tornado (4.3)
traitlets (4.2.1)
wheel (0.29.0)
widgetsnbextension (1.2.3)

I may be missing something here, but I'm not sure what. Any idea why having jupyter as a dependency in a setuptools-powered setup.py script fails here?

Best,
Aurélien

@minrk
Copy link
Member

minrk commented Jun 24, 2016

That suggests that perhaps setuptools is getting a different version when imported than pip is listing (a known bug caused by old setuptools). What do you get from:

python -c 'import setuptools; print(setuptools, setuptools.__version__)'

And also:

python -m site

It's also something that may not be familiar that if you use setuptools in setup.py, you should never do python setup.py install, only pip install ..

@ajmazurie
Copy link
Author

Here are the outputs:

$ python -c 'import setuptools; print(setuptools, setuptools.__version__)'
(<module 'setuptools' from '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/setuptools/__init__.pyc'>, '23.1.0')

and

$ python -m site
sys.path = [
    '/Users/ajmazurie/Data/Professional-MSU/2015.07-MSU-me-Jupyter_in_Classroom/Projects/Callysto/callysto',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/jupyter-1.0.0-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/ipywidgets-5.1.5-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/ipykernel-4.3.1-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/nbconvert-4.2.0-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/jupyter_console-5.0.0b1-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/qtconsole-4.2.1-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/notebook-4.2.1-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/widgetsnbextension-1.2.3-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/traitlets-4.2.1-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/ipython-5.0.0b4-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/tornado-4.3-py2.7-macosx-10.10-x86_64.egg',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages/jupyter_client-4.3.0-py2.7.egg',
    '/Users/ajmazurie/<path to python>/lib/python27.zip',
    '/Users/ajmazurie/<path to python>/lib/python2.7',
    '/Users/ajmazurie/<path to python>/lib/python2.7/plat-darwin',
    '/Users/ajmazurie/<path to python>/lib/python2.7/plat-mac',
    '/Users/ajmazurie/<path to python>/lib/python2.7/plat-mac/lib-scriptpackages',
    '/Users/ajmazurie/<path to python>/lib/python2.7/lib-tk',
    '/Users/ajmazurie/<path to python>/lib/python2.7/lib-old',
    '/Users/ajmazurie/<path to python>/lib/python2.7/lib-dynload',
    '/Users/ajmazurie/.direnv/pyenv/versions/2.7.11/lib/python2.7',
    '/Users/ajmazurie/.direnv/pyenv/versions/2.7.11/lib/python2.7/plat-darwin',
    '/Users/ajmazurie/.direnv/pyenv/versions/2.7.11/lib/python2.7/lib-tk',
    '/Users/ajmazurie/.direnv/pyenv/versions/2.7.11/lib/python2.7/plat-mac',
    '/Users/ajmazurie/.direnv/pyenv/versions/2.7.11/lib/python2.7/plat-mac/lib-scriptpackages',
    '/Users/ajmazurie/<path to python>/lib/python2.7/site-packages',
]
USER_BASE: '/Users/ajmazurie/.local' (doesn't exist)
USER_SITE: '/Users/ajmazurie/.local/lib/python2.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: False

@ajmazurie
Copy link
Author

It's also something that may not be familiar that if you use setuptools in setup.py, you should never do python setup.py install, only pip install ..

This is very interesting, and may be the sign that I need to update my knowledge on setuptools. Regardless, this fixed my issue! By typing pip install . in the folder containing my setup.py script above, I was able to successfully install Jupyter and its dependencies. Thanks!

As a side question, why did it not work with python setup.py install? I couldn't find any reference online about why this could be a problem.

Best, Aurélien

@minrk
Copy link
Member

minrk commented Jun 24, 2016

python setup.py install does the same thing as easy_install. easy_install does lots of unpleasant things, which are the reason pip was created. For backward-compatibility reasons, python setup.py install with setuptools imported will always do the undesirable things that easy_install does, and thus should never be called.

@Carreau Carreau added this to the no action milestone Jun 24, 2016
@seperman
Copy link

seperman commented Aug 1, 2016

I only get this error if I install ipython in a virtualvenv that is shared on NFS. Any clues why installing in a venv on NFS can cause this issue?

@takluyver
Copy link
Member

Not sure why NFS would make a difference, but check the version of pip inside the virtualenv, and if it's not the latest, try updating it:

pip install --upgrade setuptools pip

@seperman
Copy link

seperman commented Aug 1, 2016

@takluyver The same pip that install ipython fine in the "normal" filesystem, doesn't install it properly on NFS. And yes, it is the latest version of pip.

@takluyver
Copy link
Member

Bizarre. No idea why NFS would affect that.

@jakirkham
Copy link
Contributor

Also running into this issue with Python 2.7 using the latest pip (8.1.2) and latest setuptools (25.1.6). Is it not possible there is something more going on?

@jakirkham
Copy link
Contributor

Installing backports.shutil_get_terminal_size with pip beforehand was an effective workaround for the problem.

@jakirkham
Copy link
Contributor

As mentioned elsewhere, put PR ( paulgb/runipy#125 ) together to show the backports.shutil_get_terminal_size error and entrypoints error. The first commit shows the first error and the second commit shows the second error. In both cases, the first 3 CI builds in the matrix are of interest. All 3 of these use setuptools to install everything.

@minrk
Copy link
Member

minrk commented Aug 9, 2016

Looks like a problem in setuptools. Installing with pip (as should always be done) will fix it.

I'm not 100% sure what setuptools is failing to do, though.

@petef4
Copy link

petef4 commented Aug 11, 2016

I've just had the same sort of problem installing IPython (not Jupyter) in a fresh 2.7.3 virtualenv. IPython appeared to install but was missing pathlib2 and then backports.shutil-get-terminal-size. Doing a pip install on each fixed the dependencies and IPython is now working.

$ pip freeze
nose==1.3.7
numpy==1.8.0
pyreadline==2.1
wsgiref==0.1.2

$ pip install ipython
[...]
Successfully installed ipython setuptools decorator pickleshare simplegeneric traitlets prompt-toolkit pygments pexpect ipython-genutils six wcwidth ptyprocess
Cleaning up...

$ pip freeze
Pygments==2.1.3
decorator==4.0.10
ipython==5.0.0
ipython-genutils==0.1.0
nose==1.3.7
numpy==1.8.0
pexpect==4.2.0
pickleshare==0.7.3
prompt-toolkit==1.0.5
ptyprocess==0.5.1
pyreadline==2.1
simplegeneric==0.8.1
six==1.10.0
traitlets==4.2.2
wcwidth==0.1.7
wsgiref==0.1.2

$ ipython
[...]
pkg_resources.DistributionNotFound: The 'pathlib2' distribution was not found and is required by ipython

$ pip install pathlib2

$ ipython
[...]
pkg_resources.DistributionNotFound: The 'backports.shutil_get_terminal_size' distribution was not found and is required by ipython

$ pip install backports.shutil_get_terminal_size

$ pip freeze
Pygments==2.1.3
backports.shutil-get-terminal-size==1.0.0
decorator==4.0.10
ipython==5.0.0
ipython-genutils==0.1.0
nose==1.3.7
numpy==1.8.0
pathlib2==2.1.0
pexpect==4.2.0
pickleshare==0.7.3
prompt-toolkit==1.0.5
ptyprocess==0.5.1
pyreadline==2.1
simplegeneric==0.8.1
six==1.10.0
traitlets==4.2.2
wcwidth==0.1.7
wsgiref==0.1.2

$ ipython
Python 2.7.3 (default, Aug 11 2016, 11:06:04) 
Type "copyright", "credits" or "license" for more information.

IPython 5.0.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]: 

@takluyver
Copy link
Member

Can you do a pip --version? I'd guess you have a too old version of pip.

@petef4
Copy link

petef4 commented Aug 11, 2016

Yes you are correct. I was on pip 1.4.1.

I repeated the exercise after upgrading my virtualenv to pip 8.1.2 and IPython 5.0.0 installed without a problem.

$ pip freeze
backports.shutil-get-terminal-size==1.0.0
decorator==4.0.10
ipython==5.0.0
ipython-genutils==0.1.0
numpy==1.8.0
pathlib2==2.1.0
pexpect==4.2.0
pickleshare==0.7.3
prompt-toolkit==1.0.5
ptyprocess==0.5.1
Pygments==2.1.3
simplegeneric==0.8.1
six==1.10.0
traitlets==4.2.2
wcwidth==0.1.7

@ternus
Copy link

ternus commented Aug 12, 2016

I'm also having this problem on OS X:

cternus@astarael:~⟫ ipython
Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 7, in <module>
    from IPython import start_ipython
  File "/usr/local/lib/python2.7/site-packages/IPython/__init__.py", line 48, in <module>
    from .core.application import Application
  File "/usr/local/lib/python2.7/site-packages/IPython/core/application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "/usr/local/lib/python2.7/site-packages/IPython/core/crashhandler.py", line 28, in <module>
    from IPython.core import ultratb
  File "/usr/local/lib/python2.7/site-packages/IPython/core/ultratb.py", line 128, in <module>
    from IPython.utils.terminal import get_terminal_size
  File "/usr/local/lib/python2.7/site-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
cternus@astarael:~⟫ pip freeze | grep shutil
backports.shutil-get-terminal-size==1.0.0
cternus@astarael:~⟫ pip freeze | grep ipython
ipython==5.0.0
ipython-genutils==0.1.0
cternus@astarael:~⟫ python -m site
sys.path = [
    '/Users/cternus',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
    '/usr/local/lib/python2.7/site-packages',
    '/Library/Python/2.7/site-packages',
    '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
]
USER_BASE: '/Users/cternus/Library/Python/2.7' (doesn't exist)
USER_SITE: '/Users/cternus/Library/Python/2.7/lib/python/site-packages' (doesn't exist)
ENABLE_USER_SITE: True

I've tried doing sudo pip install --upgrade --force-reinstall ipython (as well as reinstalling pip and setuptools) with no luck.

@ternus
Copy link

ternus commented Aug 12, 2016

After some investigating, I believe the backports.shutil_get_terminal_size module itself is at fault:

cternus@astarael:/usr/local/lib/python2.7/site-packages⟫ python
Python 2.7.12 (default, Jun 29 2016, 14:05:02)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import backports
>>> dir(backports)
['__doc__', '__name__', '__path__']
>>> 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
>>>
cternus@astarael:/usr/local/lib/python2.7/site-packages⟫ ls backports
__init__.py              functools_lru_cache.py   shutil_get_terminal_size
cternus@astarael:/usr/local/lib/python2.7/site-packages⟫ ls backports/shutil_get_terminal_size
__init__.py           __init__.pyc          get_terminal_size.py  get_terminal_size.pyc
cternus@astarael:/usr/local/lib/python2.7/site-packages⟫

Interestingly, the backports module seems to install two (slightly different?!) versions of itself:

root@astarael:/usr/local/lib/python2.7/site-packages/backports⟫ pip show --no-cache -vf backports.shutil-get-terminal-size
---
Metadata-Version: 2.0
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: chrippa@tanuki.se
Installer: pip
License: MIT
Location: /usr/local/lib/python2.7/site-packages
Requires:
Classifiers:
  Development Status :: 5 - Production/Stable
  License :: OSI Approved :: MIT License
  Programming Language :: Python :: 2.6
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3.2
Files:
  backports.shutil_get_terminal_size-1.0.0.dist-info/DESCRIPTION.rst
  backports.shutil_get_terminal_size-1.0.0.dist-info/INSTALLER
  backports.shutil_get_terminal_size-1.0.0.dist-info/METADATA
  backports.shutil_get_terminal_size-1.0.0.dist-info/RECORD
  backports.shutil_get_terminal_size-1.0.0.dist-info/WHEEL
  backports.shutil_get_terminal_size-1.0.0.dist-info/metadata.json
  backports.shutil_get_terminal_size-1.0.0.dist-info/top_level.txt
  backports/__init__.py
  backports/__init__.pyc
  backports/shutil_get_terminal_size/__init__.py
  backports/shutil_get_terminal_size/__init__.pyc
  backports/shutil_get_terminal_size/get_terminal_size.py
  backports/shutil_get_terminal_size/get_terminal_size.pyc
  shutil_backports/__init__.py
  shutil_backports/__init__.pyc
  shutil_backports/get_terminal_size.py
  shutil_backports/get_terminal_size.pyc

and patching IPython/utils/terminal.py to use shutil_backports.get_terminal_size works. Go figure.

@kemathur
Copy link

kemathur commented Aug 26, 2016

Hello,

I was getting the same error in virtualenv. I had been using pip to install jupyter.

I was getting
ImportError: No module named shutil_get_terminal_size

"pip freeze" showed backports.shutil-get-terminal-size==1.0.0

So i tried upgrading. It showed:

pip install --upgrade backports.shutil-get-terminal-size
Requirement already up-to-date: backports.shutil-get-terminal-size in /Library/Python/2.7/site-packages

So it was somehow accessing my global libraries and not the one in my venv.

Then I uninstalled backports.shutil-get-terminal-size from the global python and installed it in my venev. Now it's working fine.

@AndrewHoos
Copy link

I can reproduce this 100% of the time with this install

pip install --user --upgrade ipython==4.2

I can reproduce this 0% of the time with this install

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

@minrk
Copy link
Member

minrk commented Sep 1, 2016

@AndrewHoos and for me, both commands get the dependencies correctly. What do you get from pip --version? It should be at least 8. If it is not, make sure your setuptools and pip are up to date:

pip install --upgrade setuptools pip

@pierre-haessig
Copy link
Contributor

I'm hit with this issue with notebook 4.2.2 and ipython 5.1.0 installed with conda. As mentioned above, I've the shutil_get_terminal_size already installed:

pip install backports.shutil_get_terminal_size
Requirement already satisfied (use --upgrade to upgrade): backports.shutil_get_terminal_size in /.../anaconda/lib/python2.7/site-packages

However, in regular python shell, the import backports.shutil_get_terminal_size command fails.

@pierre-haessig
Copy link
Contributor

Ok, I found a crude but simple solution: uninstall and install again. Now ipython works....

$ 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

@martynbristow
Copy link

Also ran into this problem
Sadly it took nothing above helped very much, but the problem is exactly as reported above:

ImportError: No module named shutil_get_terminal_size

Uninstalling and installing IPython and back ports was no joy.

The problem was I have Jupyter & friends installed globally, and shutil_get_terminal_size installed globally. i.e. in /Library/Python/2.7/site-packages/shutil_backports/

However I also had backports.functools_lru_cache installed locally, this actually blocked the import of shutil_backports.

To test if this is the problem: ls ~/Library/Python/2.7/lib/python/site-packages (On OSX, if you see a folder back ports, thats probably at fault. I uninstalled the library from the user library and added it into the system library. Either way you an't mix & match your back ports. It must be global or local to work fully.

@AllanDaemon
Copy link

Same problem in Debian Sid (Unstable) fully updated. I updated pip; tried to uninstall and install again from fresh; etc. Nothing worked.

# uname -a
Linux bunsen 4.7.0-1-amd64 #1 SMP Debian 4.7.2-1 (2016-08-28) x86_64 GNU/Linux
# pip2 --version
pip 8.1.2 from /usr/local/lib/python2.7/dist-packages (python 2.7)
# pip show ipython
---
Metadata-Version: 2.0
Name: ipython
Version: 5.1.0
Summary: IPython: Productive Interactive Computing
Home-page: http://ipython.org
Author: The IPython Development Team
Author-email: ipython-dev@scipy.org
Installer: pip
License: BSD
Location: /usr/local/lib/python2.7/dist-packages
Requires: pickleshare, simplegeneric, traitlets, backports.shutil-get-terminal-size, decorator, pygments, prompt-toolkit, pexpect, pathlib2, setuptools
Classifiers:
  Framework :: IPython
  Intended Audience :: Developers
  Intended Audience :: Science/Research
  License :: OSI Approved :: BSD License
  Programming Language :: Python
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3
  Topic :: System :: Shells
Entry-points:
  [console_scripts]
  iptest = IPython.testing.iptestcontroller:main
  iptest2 = IPython.testing.iptestcontroller:main
  ipython = IPython:start_ipython
  ipython2 = IPython:start_ipython
  [pygments.lexers]
  ipython = IPython.lib.lexers:IPythonLexer
  ipython3 = IPython.lib.lexers:IPython3Lexer
  ipythonconsole = IPython.lib.lexers:IPythonConsoleLexer

@Hiczeke
Copy link

Hiczeke commented Sep 18, 2016

uninstall and install backports.shutil_get_terminal_size again works.

@bdutta19
Copy link

+1 in osx. Same problem, - UnInstall global and install in virtualenv works and points to local.

@abhitrip
Copy link

@ihincks I tried all the posts but none worked. It was only yours that worked. You are a life saver :)

@irenab
Copy link

irenab commented Feb 16, 2017

fix by ihincks also works on windows 10

@Zipfer
Copy link

Zipfer commented Mar 5, 2017

I hope it can help somebody.
in my case I found the root of the issue was wrong ipython version:

ls -lah /usr/local/bin/ipython*
-rwxr-xr-x  1 z  staff   247B Mar  5 15:16 /usr/local/bin/ipython
-rwxr-xr-x  1 z  staff   247B Mar  5 15:16 /usr/local/bin/ipython3

I don't know how it can happened because I don't have a python3 version at all.
My problem was solved when I've uninstalled python and removed related libraries

brew uninstall python
rm -rf /usr/local/lib/python2.7

I've reinstalled python and make sure that pip has has correct version and location.
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)
pip2 install ipython

@likeyiyy
Copy link

@ihincks

This is the only right answer for me.

@turiya
Copy link

turiya commented Mar 13, 2017

sudo pip uninstall backports.shutil_get_terminal_size
sudo pip install backports.shutil_get_terminal_size

@Carreau
Copy link
Member

Carreau commented Mar 13, 2017 via email

@usptact
Copy link

usptact commented Apr 6, 2017

@ihincks On FreeBSD only your solution worked! Thanks a ton!

@harrisniall
Copy link

FYI, I ran into the same issue, but could only get around the shutil_get_terminal_size problem by using the --ignore-installed option in pip. Without it, the package would not reinstall correctly.

pip install --ignore-installed backports.shutil_get_terminal_size

@rtlatimer
Copy link

@AllanDaemon 's response solved the problem for me!

@banthi
Copy link

banthi commented Apr 19, 2017

Faced a similar problem and it got resolved by uninstalling and reinstalling backports.shutil_get_terminal_size

pip uninstall backports.shutil_get_terminal_size
pip install backports.shutil_get_terminal_size

@JirenJin
Copy link

I had the same problem.
After trying many solutions above, I finally found that the problem is due to my $PATH setting.
Maybe previously I had used pip install --user option, so that /home/jin/.local/lib/python2.7 was in my $PATH, where another version of backports existed.
I solved this issuse by delete the .local/lib/python2.7 folder.

To test whether it is problem with you $PATH, you can simply try

import sys
print sys.path

@martynbristow
Copy link

martynbristow commented May 1, 2017

The issue is caused by having "backports" in both "System" and "User" locations.
On my macOS I had installed shutil_get_terminal_size to in system, but I had another package installed in my user home. This user folder takes precedence and you don't search in System.
Install all your python packages, with --user is wise.
If your stuck force a reinstall to with --user:
pip install --ignore-installed backports.shutil_get_terminal_size --user
This should probably be added to some diagnostics as it bugs me everytime

@takluyver
Copy link
Member

backports is supposed to be a 'namespace package', which is allowed to have subpackages installed in different places like that. But it doesn't seem to be working reliably, and I can't figure out why. I can't reproduce it to debug locally, and my attempts to debug it on through other people have just been puzzling.

@willingc
Copy link
Member

willingc commented May 2, 2017

@takluyver Have you seen https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=843898? The last 2-3 posts are interesting.

@takluyver
Copy link
Member

Unfortunately that more or less seems like what I found - something is messing up the backports namespace package, but we can't work out what or how. Debian said, quite justifiably, that it's not their problem if pip-installed packages break things.

@mjdellwo
Copy link

mjdellwo commented May 2, 2017

I commented here chrippa/backports.shutil_get_terminal_size#9 (comment) and referenced above on finding a diffference between the wheel vs. non-wheel (non-binary) install via pip, is that anything relevant?

@Carreau
Copy link
Member

Carreau commented May 2, 2017 via email

@willingc
Copy link
Member

willingc commented May 2, 2017

Is this something that could be backported into CPython's shutil?

@Carreau
Copy link
Member

Carreau commented May 2, 2017

Is this something that could be backported into CPython's shutil?

Likely no, we are already not using the backport package on IPython 6.0/master, this is already in all CPython stables we support, and the issue only occurs because we use the backport package on 2.7 as this is not in standard CPython 2.7.

@willingc
Copy link
Member

willingc commented May 2, 2017

Got it. Thanks @Carreau. Glad it's only going to be a temporary issue.

@akanshmurthy
Copy link

akanshmurthy commented May 24, 2017

Deleting the global installation, uninstalling in virtualenv, and reinstalling in virtualenv fixed the problem for me.

@JNingWei
Copy link

JNingWei commented May 31, 2017

What you need just typing the below commands:

conda config --add channels conda-forge
conda install backports.shutil_get_terminal_size

I used to have the same problem, and this solve it.

@nicola-lunghi
Copy link

nicola-lunghi commented Nov 14, 2017

Hi
same problem on Ubuntu 17.10 with ipython2.
No Problem with python3

FIX: sudo -H pip install --ignore-installed backports.shutil_get_terminal_size

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.10
Release:	17.10
Codename:	artful

$ python --version
Python 2.7.14

$ python3 --version
Python 3.6.3

$ pip show ipython
Name: ipython
Version: 5.1.0
Summary: IPython: Productive Interactive Computing
Home-page: http://ipython.org
Author: The IPython Development Team
Author-email: ipython-dev@scipy.org
License: BSD
Location: /usr/lib/python2.7/dist-packages
Requires: backports.shutil-get-terminal-size, pathlib2, pexpect

$ pip3 show ipython
Name: ipython
Version: 5.1.0
Summary: IPython: Productive Interactive Computing
Home-page: http://ipython.org
Author: The IPython Development Team
Author-email: ipython-dev@scipy.org
License: BSD
Location: /usr/lib/python3/dist-packages
Requires: pexpect

$ 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

$ apt-cache show python-ipython
Package: python-ipython
Architecture: all
Version: 5.1.0-3
Priority: optional
Section: universe/python
Source: ipython
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1864
Depends: python-decorator, python-pexpect, python-pickleshare, python-pkg-resources, python-prompt-toolkit, python-pygments, python-simplegeneric, python-traitlets, python:any (<< 2.8), python:any (>= 2.7.5-5~), python-backports-shutil-get-terminal-size, python-pathlib2
Breaks: ipython (<< 4)
Replaces: ipython (<< 4)
Filename: pool/universe/i/ipython/python-ipython_5.1.0-3_all.deb
Size: 375048
MD5sum: 7ae68256eb7c6183634ea3680ad4449d
SHA1: 7e2916b5e661793dcb55e86404de5cd1f0d19d8b
SHA256: 0664f1d3c5543cc3ba4db4fcd8bf4526de714e3f35687b49052fad7831cbdee3
Homepage: https://github.com/ipython/ipython
Description-en: Enhanced interactive Python shell (Python 2 version)
 IPython can be used as a replacement for the standard Python shell,
 or it can be used as a complete working environment for scientific
 computing (like Matlab or Mathematica) when paired with the standard
 Python scientific and numerical tools. It supports dynamic object
 introspections, numbered input/output prompts, a macro system,
 session logging, session restoring, complete system shell access,
 verbose and colored traceback reports, auto-parentheses, auto-quoting,
 and is embeddable in other Python programs.
 .
 This package contains the backend terminal shell for Python 2: for
 the actual frontend install ipython.
Description-md5: 713480d81c0c64f1b3a9c4c9350ef96c

$ apt-cache show python3-ipython
Package: python3-ipython
Architecture: all
Version: 5.1.0-3
Priority: optional
Section: universe/python
Source: ipython
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1864
Depends: python3-decorator, python3-pexpect, python3-pickleshare, python3-pkg-resources, python3-prompt-toolkit, python3-pygments, python3-simplegeneric, python3-traitlets, python3:any (>= 3.3.2-2~), python-pexpect
Breaks: ipython3 (<< 4)
Replaces: ipython3 (<< 4)
Filename: pool/universe/i/ipython/python3-ipython_5.1.0-3_all.deb
Size: 375114
MD5sum: c0585bf56c9fbcbb73aa45d25b8fbe14
SHA1: c7118d1050f50723d614a3060ad6d8d31a96e73c
SHA256: 293217ee356c2c2623efce3fc391b1876a38585b0ae7462b2a8a0d3f3424ec86
Homepage: https://github.com/ipython/ipython
Description-en: Enhanced interactive Python shell (Python 3 version)
 IPython can be used as a replacement for the standard Python shell,
 or it can be used as a complete working environment for scientific
 computing (like Matlab or Mathematica) when paired with the standard
 Python scientific and numerical tools. It supports dynamic object
 introspections, numbered input/output prompts, a macro system,
 session logging, session restoring, complete system shell access,
 verbose and colored traceback reports, auto-parentheses, auto-quoting,
 and is embeddable in other Python programs.
 .
 This package contains the backend terminal shell for Python 3: for
 the actual frontend install ipython.
Description-md5: 8182f91eff6e0e148e574a20d31e0f51

@Carreau
Copy link
Member

Carreau commented Nov 14, 2017

@nicola-lunghi please do not advise people to use sudo pip, that's just going to break your system in weirder way in the long run. Pip will fight with system package-manager over some files.

That's the equivalent of removing the battery from your Carbon Monoxide alarm because it regularly wakes you up at night. There is something wrong with your heater; you need a proper fix.

@nicola-lunghi
Copy link

Thanks @Carreau
I will correct my answer after having extinguished the fire at my home.

Ps please fix the "heather" -> deb dependancies

@takluyver
Copy link
Member

The easiest fix is probably to install a newer version of IPython with pip install --user ipython (the --user flag means it doesn't need sudo). We already worked around this problem in IPython, but we can't control the Debian packages, and users installing through apt get an outdated version of IPython.

@rct
Copy link

rct commented Jan 25, 2018

In case someone encounters the same problem with Cygwin and python2 the solution is to run Cygwin setup.exe (or one of the apt-cyg utls) and install python2-backports.shutil_get_terminal_size. This isn't triggered as a dependency by default so it needs to be installed manually.

ipython3 is fine out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests