如何在 Jupyter IPython Notebook 中安装 Scala?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35563545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 08:02:37  来源:igfitidea点击:

How do I install Scala in Jupyter IPython Notebook?

scalajupyter

提问by Ravaal

Here's a few links that I went to and did exactly what they said. I don't know what I'm doing wrong.

这是我访问的一些链接,并且完全按照他们所说的去做。我不知道我做错了什么。

https://github.com/alexarchambault/jupyter-scala
https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages
https://github.com/apache/incubator-toree
http://jcrudy.github.io/blog/html/2013/12/08/introduction_to_iscala.html

https://github.com/alexarchambault/jupyter-scala
https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages
https://github.com/apache/incubator-toree
http ://jcrudy.github.io/blog/html/2013/12/08/introduction_to_iscala.html

None of this is working. It may be some way that my node is configured. I just don't know. Please help.

这些都不起作用。这可能是我的节点配置的某种方式。我就是不知道。请帮忙。

回答by Saqib Shamsi

You can use the information given here.

您可以使用此处提供的信息。

Ensure you have IPython 3 installed. ipython --version should return a value >= 3.0. If it's not the case, a quick way of setting it up consists in installing the Anaconda Python distribution, and then running

$ pip install --upgrade "ipython[all]"

ipython --version should then return a value >= 3.0.

Download the Jupyter Scala binaries for Scala 2.10 (txzor zip) or Scala 2.11 (txzor zip), and unpack them in a safe place. Then run once the jupyter-scala program (or jupyter-scala.bat on Windows) it contains. That will set-up the Jupyter Scala kernel for the current user.

Check that Jupyter/IPython knows about Jupyter Scala by running

$ jupyter kernelspec list

This should print, among others, a line like

scala211

(or scala210 dependending on the Scala version you chose).

Then run either IPython console with

$ ipython console --kernel scala211

and start using the Jupyter Scala kernel straightaway, or run Jupyter Notebook with

$ jupyter notebook

and create Scala 2.11 notebooks by choosing Scala 2.11 in the dropdown in the upper right of the Jupyter Notebook start page.

确保您已安装 IPython 3。ipython --version 应该返回一个 >= 3.0 的值。如果不是这种情况,设置它的快速方法包括安装 Anaconda Python 发行版,然后运行

$ pip install --upgrade "ipython[all]"

ipython --version 然后应该返回一个值 >= 3.0。

下载适用于 Scala 2.10(txzzip)或 Scala 2.11(txzzip)的 Jupyter Scala 二进制文件,并将它们解压到安全的地方。然后运行一次它包含的 jupyter-scala 程序(或 Windows 上的 jupyter-scala.bat)。这将为当前用户设置 Jupyter Scala 内核。

通过运行检查 Jupyter/IPython 是否了解 Jupyter Scala

$ jupyter kernelspec list

这应该打印,其中包括一行

Scala211

(或 scala210 取决于您选择的 Scala 版本)。

然后运行 ​​IPython 控制台

$ ipython console --kernel scala211

并立即开始使用 Jupyter Scala 内核,或运行 Jupyter Notebook

$ jupyter notebook

并通过在 Jupyter Notebook 起始页右上角的下拉列表中选择 Scala 2.11 来创建 Scala 2.11 笔记本。

Note:Since IPython has now been replaced by Jupyter, we replaced ipythonin the above commands with jupyter.

注意:由于 IPython 现在已经被 Jupyter 取代,我们ipython在上面的命令中用jupyter.

回答by Heapify

I tried the following with Jupyterhub notebook and it works seamlessly:

我在 Jupyterhub 笔记本上尝试了以下操作,它可以无缝运行:

# Step 1: Install spylon kernel
pip install spylon-kernel

# Step 2: create a kernel spec
python -m spylon_kernel install

# Step 3: start jupyter notebook 
jupyter notebook

PS: to list all installed kernels, you can run the following command:

PS:要列出所有已安装的内核,可以运行以下命令:

jupyter kernelspec list

回答by Carl Zmola

I can't add a comment to Heapify's answer, but his solution worked for JupyterLab on Windows without problems.

我无法对 Heapify 的回答添加评论,但他的解决方案适用于 Windows 上的 JupyterLab,没有问题。

I cut and pasted his code into an Anaconda Powershell prompt

我将他的代码剪切并粘贴到 Anaconda Powershell 提示符中

pip install spylon-kernel
python -m spylon_kernel install
jupyter notebook

And refreshed my anacopnda launcher and the spylon project option was available.

并刷新了我的 anacopnda 启动器,并且 spylon 项目选项可用。

回答by Mike

I've just run:

我刚刚跑了:

  • conda create --name base2 --clone baseto create an env just like base.

  • conda activate base2to move to the newenv.

  • conda install -c conda-forge spylon-kernel.

  • python -m spylon_kernel install --user. create a kernel spec for Jupyter notebook

  • jupyter-notebook

  • conda create --name base2 --clone basebase一样创建一个 env 。

  • conda activate base2移动到新的环境

  • conda install -c conda-forge spylon-kernel.

  • python -m spylon_kernel install --user. 为 Jupyter notebook 创建内核规范

  • jupyter-notebook

...and works just fine.

...而且工作得很好。

I'm using:

我正在使用:

  • Anaconda 4.7.12
  • Jupyter-notebook 6.0.1
  • Ubuntu 18.04
  • ipykernel 5.1.3
  • ipython 7.9.0
  • ipython_genutils 0.2.0
  • jupyter_client 5.3.4
  • jupyter_core 4.6.0
  • traitlets 4.3.3
  • 蟒蛇 4.7.12
  • Jupyter-笔记本 6.0.1
  • Ubuntu 18.04
  • ipykernel 5.1.3
  • 蟒蛇7.9.0
  • ipython_genutils 0.2.0
  • jupyter_client 5.3.4
  • jupyter_core 4.6.0
  • 特质 4.3.3

from def suma(a: Int) = a + 3

def suma(a: Int) = a + 3

enter image description here

在此处输入图片说明

回答by Ravaal

The answer for Linux can be found here.

可以在此处找到 Linux 的答案。

Install Scala. Add these lines to ~/.bashrc

export SCALA_HOME=/usr/local/share/scala export PATH=$PATH:$SCALA_HOME/bin:$PATH Follow these instructions from the GitHub site:

Download and unpack pre-packaged binaries Scala 2.11.Unpack each downloaded archive(s), and, from a console, go to the bin sub-directory of the directory it contains. Then run the following to set-up the corresponding Scala kernel:

./jove-scala --kernel-spec

安装斯卡拉。将这些行添加到 ~/.bashrc

export SCALA_HOME=/usr/local/share/scala export PATH=$PATH:$SCALA_HOME/bin:$PATH 按照来自 GitHub 站点的这些说明进行操作:

下载并解压预先打包好的二进制 Scala 2.11。解压缩每个下载的存档,然后从控制台转到它包含的目录的 bin 子目录。然后运行以下命令来设置相应的 Scala 内核:

./jove-scala --kernel-spec