Julia語言入門
Julia的安裝和運(yùn)行
Julia程序語言介紹
Julia程序語言是一種計(jì)算機(jī)編程語言, 就像C、C++、Fortran、Java、R、Python、Matlab等程序語言一樣。 Julia語言歷史比較短,發(fā)布于2012年,是MIT的幾位作者和全世界的參與者共同制作的。 主網(wǎng)站在https://julialang.org/。
Julia與R、Python等一樣是動(dòng)態(tài)類型語言, 程序與R、Python一樣簡單, 但是它先進(jìn)的設(shè)計(jì)使得Julia程序的效率基本達(dá)到和C、Fortran等強(qiáng)類型語言同樣的高效率。 尤其適用于數(shù)值計(jì)算,在現(xiàn)今的大數(shù)據(jù)應(yīng)用中也是特別合適的語言, 排在Python、R之后,已經(jīng)獲得廣泛的關(guān)注, 現(xiàn)在用戶較少只是因?yàn)闅v史還太短。
Julia軟件安裝和運(yùn)行
從Julia網(wǎng)站下載安裝Julia的命令行程序,稱為REPL界面。
運(yùn)行方式是在一個(gè)字符型窗口中, 在提示行julia>后面鍵入命令, 回車后在下面顯示結(jié)果。
在MS Windows操作系統(tǒng)中, 設(shè)存放Julia源程序和數(shù)據(jù)文件的目錄為, 將安裝后顯示在桌面上的Julia圖標(biāo)復(fù)制到目錄中, 從右鍵選“屬性”,將“起始位置”欄改為空白。 這樣讀寫數(shù)據(jù)和程序文件的默認(rèn)位置就是圖標(biāo)所在的目錄。
Julia源程序用.jl作為擴(kuò)展名, 為了運(yùn)行當(dāng)前目錄中的“myprog.jl”文件, 在命令行用命令
julia> include("myprog.jl")
(其中julia>是自動(dòng)顯示的提示)。
使用Jupyter前端
使用Python的時(shí)候用慣了Jupyter,并且Jupyter可以說是最優(yōu)秀的前端之一,所以就試圖為
Jupyter添加Julia內(nèi)核。
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.