Jupyter with Julia

96
陈灿贻
2018.05.28 19:08 字数 518

Julia语言入门

Julia的安装和运行

Julia程序语言介绍

Julia程序语言是一种计算机编程语言, 就像C、C++、Fortran、Java、R、Python、Matlab等程序语言一样。 Julia语言历史比较短,发布于2012年,是MIT的几位作者和全世界的参与者共同制作的。 主网站在https://julialang.org/

Julia与R、Python等一样是动态类型语言, 程序与R、Python一样简单, 但是它先进的设计使得Julia程序的效率基本达到和C、Fortran等强类型语言同样的高效率。 尤其适用于数值计算,在现今的大数据应用中也是特别合适的语言, 排在Python、R之后,已经获得广泛的关注, 现在用户较少只是因为历史还太短。

Julia软件安装和运行

从Julia网站下载安装Julia的命令行程序,称为REPL界面。

运行方式是在一个字符型窗口中, 在提示行julia>后面键入命令, 回车后在下面显示结果。

在MS Windows操作系统中, 设存放Julia源程序和数据文件的目录为, 将安装后显示在桌面上的Julia图标复制到目录中, 从右键选“属性”,将“起始位置”栏改为空白。 这样读写数据和程序文件的默认位置就是图标所在的目录。

Julia源程序用.jl作为扩展名, 为了运行当前目录中的“myprog.jl”文件, 在命令行用命令

julia> include("myprog.jl")

(其中julia>是自动显示的提示)。

使用Jupyter前端

使用Python的时候用惯了Jupyter,并且Jupyter可以说是最优秀的前端之一,所以就试图为
Jupyter添加Julia内核。

To install R on Anaconda(2/3) Jupyter Notebook :

Open 'Anaconda Command Prompt' & execute conda update notebook to update your Jupyter notebook to the most recent version.
Then install IRkernel by conda install -c r notebook r-irkernel
Now you may open R in your command prompt by running R.exe

Install all necessary R packages using the following lines in the R console by executing :

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 
'devtools', 'uuid', 'digest'))

devtools::install_github('IRkernel/IRkernel')

Finally, make the R kernel available to your Jupyter Notebook by executing:

Install only for the current user ➡ IRkernel::installspec()

For System-wide installation(all Users) ➡ IRkernel::installspec(user = FALSE)

To install Julia on Anaconda(2/3) Jupyter Notebook :

First, download Julia version 0.4 or later and run the installer. Then run the Julia application (double-click on it); the Julia Console with a julia> prompt will appear.
Now, for the most important step, open 'Anaconda Command Prompt' & execute where jupyter to see the actual path of your Jupyter Notebook. The output will be something like "C:\Users\JohnDoe\AppData\Local\Continuum\Anaconda3\bin\jupyter.exe"

Copy the above location and go to your Julia console. Now, execute the following respectively: ENV["JUPYTER"]="C:\\Users\\JohnDoe\\AppData\\Local\\Continuum\\Anaconda3\\bin\\jupyter.exe"

Pkg.add("IJulia")

Pkg.build("IJulia") (Optional, execute if further error occurs again.)

⬆ Notice that the backslashes have to be doubled when you type them as a Julia string. I've just assumed that the path is your Anaconda path with \bin\jupyter appended, but replace that with whatever where jupyter tells you.

After few minutes, in Julia console execute:

using IJulia
notebook()

Now, you can program Julia in your Anaconda Jupyter Notebook.

日记本
Web note ad 1