Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "SyntaxError: invalid syntax" with ipython2 notebook

With a recent upgrade I am now running into a serious problem with SyntaxError: invalid syntax when starting a python2.7 instance of the notebook with $ ipython2 notebook.

The error seems to originate through tornado which uses ayncio and in that library there is python3.4 syntax.

I can start with $ ipython3 notebook, but the application I am doing is using mayavi which I believe is still for python2 only.

The nasty error message is:

$ ipython2 notebook
Traceback (most recent call last):
  File "/usr/local/bin/ipython2", line 11, in <module>
    sys.exit(start_ipython())
  File "/usr/local/lib/python2.7/dist-packages/IPython/__init__.py", line 118, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 591, in launch_instance
    app.initialize(argv)
  File "<string>", line 2, in initialize
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 75, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/IPython/terminal/ipapp.py", line 305, in initialize
    super(TerminalIPythonApp, self).initialize(argv)
  File "<string>", line 2, in initialize
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 75, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/application.py", line 386, in initialize
    self.parse_command_line(argv)
  File "/usr/local/lib/python2.7/dist-packages/IPython/terminal/ipapp.py", line 300, in parse_command_line
    return super(TerminalIPythonApp, self).parse_command_line(argv)
  File "<string>", line 2, in parse_command_line
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 75, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 487, in parse_command_line
    return self.initialize_subcommand(subc, subargv)
  File "<string>", line 2, in initialize_subcommand
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 75, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 418, in initialize_subcommand
    subapp = import_item(subapp)
  File "/usr/local/lib/python2.7/dist-packages/ipython_genutils/importstring.py", line 31, in import_item
    module = __import__(package, fromlist=[obj])
  File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 48, in <module>
    from tornado import httpserver
  File "/usr/local/lib/python2.7/dist-packages/tornado/httpserver.py", line 34, in <module>
    from tornado.http1connection import HTTP1ServerConnection, HTTP1ConnectionParameters
  File "/usr/local/lib/python2.7/dist-packages/tornado/http1connection.py", line 28, in <module>
    from tornado import gen
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1236, in <module>
    import tornado.platform.asyncio
  File "/usr/local/lib/python2.7/dist-packages/tornado/platform/asyncio.py", line 33, in <module>
    import asyncio
  File "/usr/local/lib/python2.7/dist-packages/asyncio/__init__.py", line 9, in <module>
    from . import selectors
  File "/usr/local/lib/python2.7/dist-packages/asyncio/selectors.py", line 39
    "{!r}".format(fileobj)) from None
                               ^
SyntaxError: invalid syntax

What would help in my sitation? Downgrading tornado? Is there something wrong in my setup. Why is it at all possible to install asyncio under python2.7?

like image 680
Finn Årup Nielsen Avatar asked Dec 10 '15 16:12

Finn Årup Nielsen


Video Answer


1 Answers

Downgrading tornado works:

$ sudo pip install tornado==4.1
$ ipython2 notebook
[I 17:22:31.800 NotebookApp] Serving notebooks from local directory: /home/fnielsen/fnielsen/ipynb
...
like image 124
Finn Årup Nielsen Avatar answered Oct 04 '22 00:10

Finn Årup Nielsen