Jupyter-Scala笔记本继续使用NullPointerException重新启动

时间:2018-03-26 08:12:11

标签: macos scala jupyter-notebook

我正在尝试用Jupyter笔记本学习Scala。我使用Homebrew安装了Scala。

brew install scala

Scala似乎在命令行中运行良好。按照this site中给出的说明执行jupyter-scala后,我使用Scala内核启动了Jupyter Notebook。弹出以下错误。

[I 12:35:05.028 NotebookApp] Kernel started: d440cf06-8a67-468c-9da4-ec8a701e0bcf
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
    at jupyter.kernel.server.ServerApp$.apply(ServerApp.scala:174)
    at jupyter.scala.JupyterScalaApp.delayedEndpoint$jupyter$scala$JupyterScalaApp$1(JupyterScala.scala:93)
    at jupyter.scala.JupyterScalaApp$delayedInit$body.apply(JupyterScala.scala:13)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at caseapp.App$$anonfun$apply$1.apply(App.scala:47)
    at caseapp.App$$anonfun$apply$1.apply(App.scala:46)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
    at caseapp.App$class.apply(App.scala:46)
    at jupyter.scala.JupyterScalaApp.apply(JupyterScala.scala:13)
    at caseapp.AppOf.main(App.scala:121)
    at jupyter.scala.JupyterScala.main(JupyterScala.scala)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at coursier.cli.qJ.a(Unknown Source)
    at coursier.cli.qI.j(Unknown Source)
    at coursier.cli.qO.a(Unknown Source)
    at d.g.a.c(Unknown Source)
    at b.b.d_(Unknown Source)
    at d.b.d.E.g(Unknown Source)
    at d.b.e.aU.g(Unknown Source)
    at a.c.a(Unknown Source)
    at coursier.cli.qI.b(Unknown Source)
    at coursier.cli.O.b(Unknown Source)
    at b.I.d_(Unknown Source)
    at d.E.h(Unknown Source)
    at a.aH.a(Unknown Source)
    at coursier.cli.Coursier.main(Unknown Source)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at coursier.Bootstrap.main(Bootstrap.java:412)
Caused by: java.lang.NullPointerException
    at ammonite.runtime.Classpath$.classpath(Classpath.scala:31)
    at ammonite.interp.Interpreter.init(Interpreter.scala:93)
    at ammonite.interp.Interpreter.processModule(Interpreter.scala:409)
    at ammonite.interp.Interpreter$$anonfun$10.apply(Interpreter.scala:151)
    at ammonite.interp.Interpreter$$anonfun$10.apply(Interpreter.scala:148)
    at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:733)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:732)
    at ammonite.interp.Interpreter.<init>(Interpreter.scala:148)
    at jupyter.scala.Interp$$anon$3.<init>(Interp.scala:41)
    at jupyter.scala.Interp.<init>(Interp.scala:41)
    at jupyter.scala.JupyterScalaApp$$anon$5.apply(JupyterScala.scala:98)
    at jupyter.scala.JupyterScalaApp$$anon$5.apply(JupyterScala.scala:97)
    at jupyter.kernel.server.Server$.launch(Server.scala:80)
    at jupyter.kernel.server.Server$.apply(Server.scala:123)
    at jupyter.kernel.server.ServerApp$$anonfun$4.apply(ServerApp.scala:171)
    at jupyter.kernel.server.ServerApp$$anonfun$4.apply(ServerApp.scala:171)
    at scala.util.Try$.apply(Try.scala:192)
    at jupyter.kernel.server.ServerApp$.apply(ServerApp.scala:171)
    ... 36 more
[I 12:35:11.027 NotebookApp] KernelRestarter: restarting kernel (1/5)
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
    at jupyter.kernel.server.ServerApp$.apply(ServerApp.scala:174)
    at jupyter.scala.JupyterScalaApp.delayedEndpoint$jupyter$scala$JupyterScalaApp$1(JupyterScala.scala:93)
    at jupyter.scala.JupyterScalaApp$delayedInit$body.apply(JupyterScala.scala:13)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at caseapp.App$$anonfun$apply$1.apply(App.scala:47)
    at caseapp.App$$anonfun$apply$1.apply(App.scala:46)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
    at caseapp.App$class.apply(App.scala:46)
    at jupyter.scala.JupyterScalaApp.apply(JupyterScala.scala:13)
    at caseapp.AppOf.main(App.scala:121)
    at jupyter.scala.JupyterScala.main(JupyterScala.scala)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at coursier.cli.qJ.a(Unknown Source)
    at coursier.cli.qI.j(Unknown Source)
    at coursier.cli.qO.a(Unknown Source)
    at d.g.a.c(Unknown Source)
    at b.b.d_(Unknown Source)
    at d.b.d.E.g(Unknown Source)
    at d.b.e.aU.g(Unknown Source)
    at a.c.a(Unknown Source)
    at coursier.cli.qI.b(Unknown Source)
    at coursier.cli.O.b(Unknown Source)
    at b.I.d_(Unknown Source)
    at d.E.h(Unknown Source)
    at a.aH.a(Unknown Source)
    at coursier.cli.Coursier.main(Unknown Source)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at coursier.Bootstrap.main(Bootstrap.java:412)
Caused by: java.lang.NullPointerException
    at ammonite.runtime.Classpath$.classpath(Classpath.scala:31)
    at ammonite.interp.Interpreter.init(Interpreter.scala:93)
    at ammonite.interp.Interpreter.processModule(Interpreter.scala:409)
    at ammonite.interp.Interpreter$$anonfun$10.apply(Interpreter.scala:151)
    at ammonite.interp.Interpreter$$anonfun$10.apply(Interpreter.scala:148)
    at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:733)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:732)
    at ammonite.interp.Interpreter.<init>(Interpreter.scala:148)
    at jupyter.scala.Interp$$anon$3.<init>(Interp.scala:41)
    at jupyter.scala.Interp.<init>(Interp.scala:41)
    at jupyter.scala.JupyterScalaApp$$anon$5.apply(JupyterScala.scala:98)
    at jupyter.scala.JupyterScalaApp$$anon$5.apply(JupyterScala.scala:97)
    at jupyter.kernel.server.Server$.launch(Server.scala:80)
    at jupyter.kernel.server.Server$.apply(Server.scala:123)
    at jupyter.kernel.server.ServerApp$$anonfun$4.apply(ServerApp.scala:171)
    at jupyter.kernel.server.ServerApp$$anonfun$4.apply(ServerApp.scala:171)
    at scala.util.Try$.apply(Try.scala:192)
    at jupyter.kernel.server.ServerApp$.apply(ServerApp.scala:171)
    ... 36 more

内核不断无限重启。

我尝试在任何地方搜索解决方案,但似乎找不到解决方案。即使重新安装jupyter-scala内核也无济于事。还有其他替代方法可以为Scala安装Jupyter内核吗?

我是Scala的新手。我该怎么办?

系统规格:MacBook,OS X El Capitan; Jupyter装置是Anaconda的一部分; Java版本9。

1 个答案:

答案 0 :(得分:3)

找出问题所在:

  

应该使用JDK 8而不是JDK 9.

~/.profile中设置Java 8通过将以下行添加到export JAVA_HOME=`/usr/libexec/java_home -v 1.8` 来解决了这个问题。

jupyter-scala

详情:

main website中声明Java 8是运行Scala的必要条件。通过Homebrew安装后,Scala似乎在终端中运行良好,即使使用Java 9.直接从解压缩的binaries运行Scala也可以正常工作。所以我从不怀疑Java版本是麻烦。

作为最后的手段,我通过Homebrew安装了Java 8(使其工作为another story),结果证明这是必需的解决方案。我认为最新的Scala已经可以处理Java 9,但PageSetup包只能处理Java 8。