简体   繁体   English

Jupyter 笔记本中的 Julia.jl

[英]Julia .jl in Jupyter notebook

I'm new to Julia, I have a file called "example.jl" and I want to open it in Jupyter.我是 Julia 的新手,我有一个名为“example.jl”的文件,我想在 Jupyter 中打开它。 I added the Julia kernel to my jupyter kernels.我将 Julia kernel 添加到我的 jupyter 内核中。 My question is: Is there a terminal command like:我的问题是:是否有像这样的终端命令:

jupyter notebook blabla.ipynb [that I use to open my notebooks] jupyter notebook blabla.ipynb [我用来打开我的笔记本]

Which opens my "example.jl" script in my jupyter notebook with the right jl kernel?在我的 jupyter notebook 中用正确的 jl kernel 打开我的“example.jl”脚本?

I looked into many pages and couldn't find an answer.我查看了很多页面,找不到答案。

PS: What I do now is to open a notebook with jl kernel and copy the Julia script into it. PS:我现在做的是打开一个jl kernel的notebook,将Julia的脚本复制进去。 But I'd like to know if there are more elegant ways to open.jl s.但我想知道是否有更优雅的方法来 open.jl s。

Generally you need to create a new empty Jupyter notebook with Julia kernel and copy-paste your code there.通常,您需要使用 Julia kernel 创建一个新的空 Jupyter 笔记本并将您的代码复制粘贴到那里。

There is also a nice Julia implementation - Weave.jl .还有一个不错的 Julia 实现 - Weave.jl Since Jupyter's format is more complex, special code formatting is required (for hints see pictures at https://github.com/JunoLab/Weave.jl ) - once it is done you can do the conversion in the following way:由于 Jupyter 的格式更复杂,因此需要特殊的代码格式(有关提示,请参阅https://github.com/JunoLab/Weave.jl中的图片)——完成后,您可以按以下方式进行转换:

convert_doc("examples/some_code.jl", "some_notebook.ipynb")

There are some other (usually Python-based) tools available, that under some circumstances can be used to split source code file into several Jupyter cells but again every time this assumes some specific code formatting.还有一些其他的(通常是基于 Python 的)工具可用,在某些情况下可以用来将源代码文件拆分成几个 Jupyter 单元格,但每次这都假定了一些特定的代码格式。

PS If you are looking for and IDE try Visual Studio Code with Julia extension which is great. PS 如果您正在寻找 IDE,请尝试带有 Julia 扩展名的 Visual Studio Code,这很棒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM