当前位置:  开发笔记 > 编程语言 > 正文

使用ipython2 notebook获取"SyntaxError:invalid syntax"

如何解决《使用ipython2notebook获取"SyntaxError:invalidsyntax"》经验,为你挑选了1个好方法。

随着最近的升级,我现在遇到一个严重的问题,SyntaxError: invalid syntax当启动笔记本的python2.7实例时$ ipython2 notebook.

该错误似乎源于tornado使用ayncio和在该库中有python3.4语法.

我可以开始$ ipython3 notebook,但我正在使用的应用程序正在使用mayavi我认为仍然只用于python2.

令人讨厌的错误消息是:

$ ipython2 notebook
Traceback (most recent call last):
  File "/usr/local/bin/ipython2", line 11, in 
    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 "", 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 "", 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 "", 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 "", 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 
    from tornado import httpserver
  File "/usr/local/lib/python2.7/dist-packages/tornado/httpserver.py", line 34, in 
    from tornado.http1connection import HTTP1ServerConnection, HTTP1ConnectionParameters
  File "/usr/local/lib/python2.7/dist-packages/tornado/http1connection.py", line 28, in 
    from tornado import gen
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1236, in 
    import tornado.platform.asyncio
  File "/usr/local/lib/python2.7/dist-packages/tornado/platform/asyncio.py", line 33, in 
    import asyncio
  File "/usr/local/lib/python2.7/dist-packages/asyncio/__init__.py", line 9, in 
    from . import selectors
  File "/usr/local/lib/python2.7/dist-packages/asyncio/selectors.py", line 39
    "{!r}".format(fileobj)) from None
                               ^
SyntaxError: invalid syntax

什么会对我的作品有所帮助?降级龙卷风?我的设置有问题吗?为什么在python2.7下安装asyncio是可能的呢?



1> Finn Årup Ni..:

降级龙卷风的工作原理:

$ sudo pip install tornado==4.1
$ ipython2 notebook
[I 17:22:31.800 NotebookApp] Serving notebooks from local directory: /home/fnielsen/fnielsen/ipynb
...


请注意,这并不能解决潜在的问题.更好的是它似乎用'trollius`交换`asyncio`:`$ sudo pip2卸载asyncio`然后是`$ sudo pip2 install tr​​ollius`.`tornado`(4.1和4.3)和`notebook`在此之后工作.
推荐阅读
有风吹过best
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有