Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipython3 does not work in the terminal with python3.7

I recently upgraded from Python3.6 to Python3.7. Since I have upgraded, when I type in ipython3 in the terminal I get an error:

~$ ipython3
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/IPython/__init__.py", line 48, in <module>
    from .core.application import Application
  File "/usr/lib/python3/dist-packages/IPython/core/application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "/usr/lib/python3/dist-packages/IPython/core/crashhandler.py", line 28, in <module>
    from IPython.core import ultratb
  File "/usr/lib/python3/dist-packages/IPython/core/ultratb.py", line 124, in <module>
    from IPython.utils import path as util_path
  File "/usr/lib/python3/dist-packages/IPython/utils/path.py", line 18, in <module>
    from IPython.utils.process import system
  File "/usr/lib/python3/dist-packages/IPython/utils/process.py", line 19, in <module>
    from ._process_posix import system, getoutput, arg_split, check_pid
  File "/usr/lib/python3/dist-packages/IPython/utils/_process_posix.py", line 24, in <module>
    import pexpect
  File "/usr/lib/python3/dist-packages/pexpect/__init__.py", line 75, in <module>
    from .pty_spawn import spawn, spawnu
  File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 14, in <module>
    from .spawnbase import SpawnBase
  File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 224
    def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
                                                                   ^
SyntaxError: invalid syntax

Furthermore I have noticed that my jupyter-notebook does not seem to work with the python3 kernel now as well (I get the kernel dead error).

NOTEs:

  • ipython and jupyter-notebook are working with fine when I use them with Python2.
  • I am using Ubuntu 18.04 (Bionic Beaver) although I don't think this is relevant
like image 448
piccolo Avatar asked Jan 27 '19 16:01

piccolo


2 Answers

async is a reserved keyword in python3.7 and an old version of pexpect is using async as variable. The solution is to upgrade pexpect.

For me, it was conflicting with apt-get installed python3, so I had to first uninstall it/them:

sudo apt-get remove python-pexpect python3-pexpect

And then

sudo pip3.7 install --upgrade pexpect

like image 96
Onilton Maciel Avatar answered Nov 07 '22 20:11

Onilton Maciel


UPDATE Please update your installed packages. This error for pexpect has been reported and closed already issue


In Python 3.7, async and await are now reserved keywords. This is what is breaking some of your installed packages.

If you do not need the new features in 3.7, roll back to 3.6 and wait until your packages are updated to support the new syntax in 3.7

What's New in Python 3.7

like image 6
kentwait Avatar answered Nov 07 '22 21:11

kentwait