0x00 前言
近期Julia這門語言突然被拉入了大衆視野,我也是被一句 “Walk as Python,Run as C” 深深的吸引住了,
如果它沒有在吹牛,那麼這門語言說不定確實是我所想要的,那麼,學學看吧?
本篇文章主要用於介紹如何搭建便於學習與測試的REPL環境,先在Linux上試試水,
畢竟一旦Jupyter Notebook搭建起來之後,網頁版的交互式環境就已經可以不受操作系統限制了。
Julia?
+ 要像C語言一般快速而有擁有如同Ruby的動態性;
+ 要具有Lisp般真正的同像性(Homoiconicity)
+ 而又有Matlab般熟悉的數學記號;
+ 要像Python般通用、
+ 像R般在統計分析上得心應手、
+ 像Perl般自然地處理字符串、
+ 像Matlab般具有強大的線性代數運算能力、
+ 像shell般膠水語言的能力,易於學習而又不讓真正的黑客感到無聊;
+ 還有,它應該是交互式的,同時又是編譯型的……
emmmm,那還說啥呢,學學看唄(不就是配個環境麼,配起來!)
0x01 相關資料
- 官方主頁
https://julialang.org/downloads/ - 官方Github
https://github.com/JuliaLang/julia - 官方文檔
https://docs.julialang.org/en/stable/manual/getting-started/
0x02 配置過程
我的環境
Anaconda2
下直接new了一個virtual env,叫做cd
- Linux RedHat
- Python 3.6
- pip 18.0
- jupyter notebook
Jupyter Notebook
一種可交互界面化變成的解決方案,Python和Julia的學習中比較推薦使用
- 預先準備 notebook
(cd) [chend@c9 ~]$ pip install notebook
- 如需使用 jupyterlab (功能更多,界面較好)
(cd) [chend@c9 ~]$ pip install jupyterlab
(cd) [chend@c9 ~]$ jupyter serverextension enable --py jupyterlab
下載
- 可以自己下載自己解壓,見
0x01 相關資料
中的官方主頁
wget https://julialang-s3.julialang.org/bin/linux/x64/1.0/julia-1.0.0-linux-x86_64.tar.gz
- 也可以直接去官方的 Github 上 git clone
git clone git://github.com/JuliaLang/julia.git
- git clone 不下來的話需要繞過的,可以全局替換一下變成ipv6通道
git config --global url."https://".insteadOf git://
獲取 cmake
編譯需要 cmake,如果沒有或者版本不對的話,可以進到剛纔下載的目錄裏面 cd julia
使用自帶的 cmake 下載腳本:
(cd) [chend@c9 julia]$ contrib/download_cmake.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 479 100 479 0 0 227 0 0:00:02 0:00:02 --:--:-- 429
1 29.2M 1 492k 0 0 2443 0 3:29:18 0:03:26 3:25:52 0
curl: (28) Operation too slow. Less than 1 bytes/sec transferred the last 15 seconds
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 29.2M 100 29.2M 0 0 421k 0 0:01:11 0:01:11 --:--:-- 450k
cmake-3.7.1-Linux-x86_64.tar.gz: OK
安裝
我這裏想要安裝剛 Release 的較爲穩定的 v1.0.0版本,所以我先 git co
到這個分支
git checkout v1.0.0
然後直接 make
就可以編譯了,但考慮到東西較多速度不夠快,也可以採取多線程編譯 make -j48
(cd) [chend@c9 julia]$ make
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 465 100 465 0 0 180 0 0:00:02 0:00:02 --:--:-- 476
1 24.3M 1 288k 0 0 7013 0 1:00:45 0:00:42 1:00:03 10783
0x03 基本使用
在當前目錄下直接 ./julia
就可以調出類似 IPython
的交互式界面了
(cd) [chend@c9 julia]$ ./julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.0.0 (2018-08-08)
_/ |\__'_|_|_|\__'_| |
|__/ |
julia>
如需在任何位置都可以直接調用 julia
命令,可以直接在 ~/.bashrc
中加入這行
echo "alias julia='/path/to/install/folder/bin/julia'" >> ~/.bashrc && source ~/.bashrc
例如我直接獲取目錄位置 pwd
是 /home/chend/julia/
,那麼我就輸入下面這行即可。
echo "alias julia='/home/chend/julia/julia'" >> ~/.bashrc && source ~/.bashrc
0x04 配置 Julia Notebook
配置 Jupyter 相關博客:
https://www.analyticsvidhya.com/blog/2017/10/comprehensive-tutorial-learn-data-science-julia-from-scratch/
我的調試過程:
julia> using IJulia
ERROR: ArgumentError: Package IJulia not found in current path:
- Run `Pkg.add("IJulia")` to install the IJulia package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:817
julia> Pkg.add("IJulia")
ERROR: UndefVarError: Pkg not defined
Stacktrace:
[1] top-level scope at none:0
# Pkg not defined 錯誤處理
julia> using Pkg
# 再次嘗試調用 IJulia
julia> using IJulia
[ Info: Precompiling IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a]
ERROR: LoadError: Blosc not installed properly, run Pkg.build("ZMQ"), restart Julia and try again
# 錯誤處理
julia> Pkg.build("ZMQ")
# 再次嘗試調用 IJulia
julia> using IJulia
[ Info: Precompiling IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a]
ERROR: LoadError: MbedTLS not installed properly, run Pkg.build("MbedTLS"), restart Julia and try again
# 錯誤處理
julia> Pkg.build("MbedTLS")
# 再次嘗試調用 Ijulia
julia> using IJulia
[ Info: Precompiling IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a]
julia> notebook()
# 完成,直接開個瀏覽器看看 localhost:8888,如果自己設定過默認端口則改爲你自己的端口。