'jupyter-console fails to start, but jupyter-notebook is fine

I can start jupyter-notebook but not jupyter-console. In the dev virtualenv on a Mac, it tries to import cast_unicode_py2 from IPython.utils.py3compat, but cast_unicode_py2 can't be imported:

(dev) C02ZV35VLVDL:profile_default harvey$ jupyter-console
Traceback (most recent call last):
  File "/Users/harvey/dev/bin/jupyter-console", line 5, in <module>
    from jupyter_console.app import main
  File "/Users/harvey/dev/lib/python3.7/site-packages/jupyter_console/app.py", line 26, in <module>
    from jupyter_console.ptshell import ZMQTerminalInteractiveShell
  File "/Users/harvey/dev/lib/python3.7/site-packages/jupyter_console/ptshell.py", line 22, in <module>
    from IPython.utils.py3compat import cast_unicode_py2, input
ImportError: cannot import name 'cast_unicode_py2' from 'IPython.utils.py3compat' (/Users/harvey/dev/lib/python3.7/site-packages/IPython/utils/py3compat.py)


Solution 1:[1]

Short answer:

As a temporary workaround you can change line 22 of jupyter_console/jupyter_console/ptshell.py to read:

from ipython_genutils.py3compat import cast_unicode_py2, input

On your computer, the file to edit is /Users/harvey/dev/lib/python3.7/site-packages/jupyter_console/ptshell.py.

Longer answer:

Jupyter console is trying to import cast_unicode_py2 and input from IPython.utils.py3compat but they've been moved to ipython_genutils.py3compat. This hasn't been fixed yet in the master branch of Jupyter console.

Solution 2:[2]

After downgrading ipython to the previous version it worked again. I guess cast_unicode_py2 is deprecated.

Solution 3:[3]

Something is out of whack in anaconda now because even with a brand new virtual environment, jupyter-console produces same type of error, even though the ptshell.py file was already changed on the source server to the format you recommend. I see

Traceback (most recent call last):
  File "/home/pauljohn/LinuxDownloads/anaconda3/envs/fuzzymatch/bin/jupyter-console", line 7, in <module>
    from jupyter_console.app import main
  File "/home/pauljohn/LinuxDownloads/anaconda3/envs/fuzzymatch/lib/python3.7/site-packages/jupyter_console/app.py", line 26, in <module>
    from jupyter_console.ptshell import ZMQTerminalInteractiveShell
  File "/home/pauljohn/LinuxDownloads/anaconda3/envs/fuzzymatch/lib/python3.7/site-packages/jupyter_console/ptshell.py", line 22, in <module>
    from IPython.utils.py3compat import cast_unicode_py2, input
ImportError: cannot import name 'cast_unicode_py2' from 'IPython

Does this output give you enough info to guess what is wrong?

$ conda list --explicit
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
@EXPLICIT
https://repo.anaconda.com/pkgs/main/linux-64/_libgcc_mutex-0.1-main.conda
https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2019.11.27-0.conda
https://repo.anaconda.com/pkgs/main/linux-64/ld_impl_linux-64-2.33.1-h53a641e_7.conda
https://repo.anaconda.com/pkgs/main/linux-64/libstdcxx-ng-9.1.0-hdf63c60_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libgcc-ng-9.1.0-hdf63c60_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/expat-2.2.6-he6710b0_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/gmp-6.1.2-h6c8ec71_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/icu-58.2-h9c2bf20_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/jpeg-9b-h024ee3a_2.conda
https://repo.anaconda.com/pkgs/main/linux-64/libffi-3.2.1-hd88cf55_4.conda
https://repo.anaconda.com/pkgs/main/linux-64/libsodium-1.0.16-h1bed415_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libuuid-1.0.3-h1bed415_2.conda
https://repo.anaconda.com/pkgs/main/linux-64/libxcb-1.13-h1bed415_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/ncurses-6.1-he6710b0_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/openssl-1.1.1d-h7b6447c_3.conda
https://repo.anaconda.com/pkgs/main/linux-64/pcre-8.43-he6710b0_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/xz-5.2.4-h14c3975_4.conda
https://repo.anaconda.com/pkgs/main/linux-64/zlib-1.2.11-h7b6447c_3.conda
https://repo.anaconda.com/pkgs/main/linux-64/glib-2.63.1-h5a9c865_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libedit-3.1.20181209-hc058e9b_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libpng-1.6.37-hbc83047_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libxml2-2.9.9-hea5a465_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/pandoc-2.2.3.2-0.conda
https://repo.anaconda.com/pkgs/main/linux-64/readline-7.0-h7b6447c_5.conda
https://repo.anaconda.com/pkgs/main/linux-64/tk-8.6.8-hbc83047_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/zeromq-4.3.1-he6710b0_3.conda
https://repo.anaconda.com/pkgs/main/linux-64/dbus-1.13.12-h746ee38_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/freetype-2.9.1-h8a8886c_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/gstreamer-1.14.0-hb453b48_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/sqlite-3.30.1-h7b6447c_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/fontconfig-2.13.0-h9420a91_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/gst-plugins-base-1.14.0-hbbd80ab_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/python-3.7.6-h0371630_2.conda
https://repo.anaconda.com/pkgs/main/noarch/attrs-19.3.0-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/backcall-0.1.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/certifi-2019.11.28-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/decorator-4.4.1-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/noarch/defusedxml-0.6.0-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/entrypoints-0.3-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/ipython_genutils-0.2.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/markupsafe-1.1.1-py37h7b6447c_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/mistune-0.8.4-py37h7b6447c_0.conda
https://repo.anaconda.com/pkgs/main/noarch/more-itertools-8.0.2-py_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pandocfilters-1.4.2-py37_1.conda
https://repo.anaconda.com/pkgs/main/noarch/parso-0.5.2-py_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pickleshare-0.7.5-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/prometheus_client-0.7.1-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/ptyprocess-0.6.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pyzmq-18.1.0-py37he6710b0_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/qt-5.9.7-h5867ecd_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/send2trash-1.5.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/sip-4.19.8-py37hf484d3e_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/six-1.13.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/testpath-0.4.4-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/tornado-6.0.3-py37h7b6447c_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/wcwidth-0.1.7-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/webencodings-0.5.1-py37_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/jedi-0.15.2-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pexpect-4.7.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pyqt-5.9.2-py37h05f1152_2.conda
https://repo.anaconda.com/pkgs/main/linux-64/pyrsistent-0.15.6-py37h7b6447c_0.conda
https://repo.anaconda.com/pkgs/main/noarch/python-dateutil-2.8.1-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/setuptools-44.0.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/terminado-0.8.3-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/traitlets-4.3.3-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/zipp-0.6.0-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/bleach-3.1.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/importlib_metadata-1.3.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/jinja2-2.10.3-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/jupyter_core-4.6.1-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/pygments-2.5.2-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/wheel-0.33.6-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/jsonschema-3.2.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/jupyter_client-5.3.4-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pip-19.3.1-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/prompt_toolkit-2.0.9-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/ipython-7.11.1-py37h39e3cac_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/nbformat-4.4.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/ipykernel-5.1.3-py37h39e3cac_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/nbconvert-5.6.1-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/jupyter_console-6.0.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/notebook-6.0.2-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/qtconsole-4.6.0-py_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/widgetsnbextension-3.5.1-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/ipywidgets-7.5.1-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/jupyter-1.0.0-py37_7.conda.utils.py3compat' (/home/pauljohn/LinuxDownloads/anaconda3/envs/fuzzymatch/lib/python3.7/site-packages/IPython/utils/py3compat.py)

Solution 4:[4]

This has been fixed as of jupyter console 6.1.0 and available via conda.

Solution 5:[5]

In some cases it helps to

pip install ipython-genutils

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 CEH
Solution 3 pauljohn32
Solution 4 Christopher Pitt Wolfe
Solution 5 Yunnosch