Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython console can't locate "backports.shutil_get_terminal_size" and won't load

I'm running Python2.7 on windows 10 doing env and most pkg management with Anaconda. After upgrading a number of packages, my ipython console now fails to start in any IDE or at the console. When I attempt to run it at the console I get this error:

Traceback (most recent call last):
File "C:\Anaconda3\Scripts\ipython-script.py", line 3, in <module>
import IPython
File "C:\Anaconda3\lib\site-packages\IPython\__init__.py", line 48, in  <module>
from .core.application import Application
File "C:\Anaconda3\lib\site-packages\IPython\core\application.py", line 24, in <module>
from IPython.core import release, crashhandler
File "C:\Anaconda3\lib\site-packages\IPython\core\crashhandler.py", line 28, in <module>
from IPython.core import ultratb
File "C:\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 121, in <module>
from IPython.utils.terminal import get_terminal_size
File "C:\Anaconda3\lib\site-packages\IPython\utils\terminal.py", line 27, in <module>
import backports.shutil_get_terminal_size
ImportError: No module named backports.shutil_get_terminal_size

The first thing I tried to do was:

pip install --upgrade backports.shutil_get_terminal_size

output:

Requirement already up-to-date: backports.shutil_get_terminal_size in c:\anaconda3\lib\site-packages

I've uninstalled and reinstalled ipython with both

conda uninstall ipython
conda install ipython

and

pip uninstall ipython
pip install ipython

Still won't work. Help please!

like image 445
Rob Truxal Avatar asked May 14 '16 22:05

Rob Truxal


3 Answers

Try this

conda config --add channels conda-forge
conda install backports.shutil_get_terminal_size
like image 197
rjmohit Avatar answered Oct 17 '22 03:10

rjmohit


I am on CentOS 7, and I needed to change my terminal.py as shown below.

On the import statements I messed around with the prefixes and got it to work -

import os
import sys
import warnings
try:
  from backports import get_terminal_size as _get_terminal_size
except ImportError:
  # use backport on Python 2
  from shutil_backports import get_terminal_size as _get_terminal_size
like image 24
Mike Avatar answered Oct 17 '22 01:10

Mike


According to this thread this is due to a bug in conda which leads to a conflict with pip installs and can be solved with a force re-install. For the thread author, $ conda install --force ipython solved the issue, for me it was $ conda install --force backports.

like image 39
christianbrodbeck Avatar answered Oct 17 '22 01:10

christianbrodbeck