前言


原本在 python 裡安裝 Jupyter 環境並不是什麼大事, 不過因為最近微軟的底層 library (ucrtbase.dll) 當中的 fmod() 函數, 修正修出了一個 bug (只要 Win10 更新至 2004 及 20H2 就會出現, 參考: 微軟 developercommunity 網站), 使得眾多需要用它的軟體 (例如: 線性代數函數庫) 都出了問題. 並且要到下一次更新時才會解決 (20H2 的下一個版本) 因此整個使用 windows 平台的 AI 及大數據相關的底層函數庫不得不做出一些更動. 像是 numpy 就決定: 原本最新的版本 1.19.4 不更動, 等候 MS 把問題解決, 問題就自解了 (因為其他平台並沒有這個問題); 但是相對的, 為了讓 Windows 平台上必需使用 numpy 的其他套件可以有暫時的解決方案, 而更動了 1.19.3 版進行暫時性的修補.

2021-01-13 更新:
numpy 已經釋出 1.19.5, 上述問題已經由新版的底層 OpenBLAS 函數庫解決. Windows 用戶安裝 numpy 已經不需再另行指定版本. (但是還是要注意是否避開了 1.19.4) MS 的修正應該是會隨著 21H1 一起發布.

以下, 我們先進行一般的安裝方式進行說明, 再針對如何解決這次的問題 (指定安裝特定的版本) 進行說明.

正常版


Jupyter 的相依套件實在有點多 (再加上我們又會要安裝許多其他的 package), 其實並不建議使用者直接安裝. 而是應該在虛擬環境裡安裝比較好.

所以我們的第一個步驟是先建立一個 python 虛擬環境, 並啟動該虛擬環境再進行安裝 Jupyter. 我們這裡以 python 原生的虛擬環境模組 venv 為例:

python -m venv vLAB
vLAB\Scripts\activate

再來就是安裝 Jupyter 了. 不過由於 Jupyter 有點歷史了, 而且每次的大更動都是換一個套件名稱, 所以你在網路上應該看到:

  • 有人教的是 jupyter (這個最舊, 主要包含 Julia, Python, R...等多種語言共用的 REPL 核心 (read-eval-print loop environment) 部份)
  • 也有人教的是 notebook (這個次之)
  • 或者是 jupyterlab

這裡建議大家不要再用那二個舊的了, 個人認為 jupyterlab 的 web 介面比較好用一些. 如果你是老用戶了, 新 UI 真的用不習慣, 也可以開啟舊版的介面(註一). 所以還是裝 jupyterlab 吧! 另外還有一個 jupyterhub, 它是用於架設多人團隊使用的 Jupyter 伺服器. 如果我們想要在安裝 jupyterhub 的機器上也可以直接使用 jupyterlab, 那伺服器主機還是需要安裝 jupyterlab(註二). 所以我們先暫時不理它, 等需要用時再研究吧!

另外, 許多人安裝 Jupyter 的最大原因是需要進行一些 AI 或者大數據的學習或研究, 所以在這裡我們把一些比較基本常用的 python package 也一併安裝起來. 例如: numpy, pandas, matplotlib..., 這裡就以這三個 packages 為例:

請在 python 虛擬環境裡執行以下指令(註三):

pip install jupyterlab pandas matplotlib

就這樣, 一行搞定. 裝好了之後, 啟動 jupyterlab 的新介面:

jupyter lab
Jupyterlab Start Up cmd screen

jupyterlab 啟動時的 cmd 畫面

註一: 舊版的 notebook 介面可以由下拉選單 'Help' --> 'Launch Classic Notebook' 開啟. 或者只啟動舊介面也是可以的:

jupyter notebook

註二: jupyterhub 是以 proxy 為主體. 當 user 完成認證之後, jupyterhub 會為 user 生成 (spawn) 並代理 (proxy) 一個 jupyter server, 再將該 jupyter server 的 proxy 連線 URL 傳給使用者.

註三: numpypandas, matplotlib 二者共同需求的套件, 所以並不需要另外特別寫明要安裝.

fmod() bug


前言所述: 由於 fmod() 的 bug, 我們在 windows 平台上用的 numpy 暫時只能安裝 1.19.3 這個版本. 所以安裝時必需早於其他需要 numpy 的套件並指定版本.

pip install jupyterlab
pip install numpy==1.19.3
pip install pandas matplotlib

或者只要在安裝的指令裡多加入 numpy 並指定版本, 我們也可以像最前面那樣: 一行指令搞定安裝.

pip install jupyterlab numpy==1.19.3 pandas matplotlib

解 python 剛出新版, 部份 package 無法安裝的問題


另一個在安裝 numpy 時可能會遇到問題 (不是 bug) 是 python 剛出新版, numpy 還沒來得及出所謂的 wheel 版本 (編譯打包好的版本). 其實其他 package (甚至是非 python 套件) 也可能會遇到這種沒有編譯好的版本可用的狀況 (也都一樣可以用下面的方法解決).

像十月份 python 3.9.0 剛出來時, 我在安裝 numpy 時就遇到了. (不過, 下面的錯誤訊息是網路剪來的, 因為我自己的當下錯過了, 沒能把它 copy 下來)

C:\Users\User001>pip install numpy
Collecting numpy
  Using cached numpy-1.19.4.zip (7.3 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\User001\appdata\local\programs\python\python39\python.exe' 'C:\Users\User001\appdata\local\programs\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\User001\AppData\Local\Temp\tmpmtdh020c'
         cwd: C:\Users\User001\AppData\Local\Temp\pip-install-c07n3_wi\numpy
    Complete output (200 lines):
    Running from numpy source directory.
    setup.py:470: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
      run_build = parse_setuppy_commands()
    Processing numpy/random\_bounded_integers.pxd.in
    Processing numpy/random\bit_generator.pyx
    Processing numpy/random\mtrand.pyx
    Processing numpy/random\_bounded_integers.pyx.in
    Processing numpy/random\_common.pyx
    Processing numpy/random\_generator.pyx
    Processing numpy/random\_mt19937.pyx
    Processing numpy/random\_pcg64.pyx
    Processing numpy/random\_philox.pyx
    Processing numpy/random\_sfc64.pyx
    Cythonizing sources
    blas_opt_info:
    blas_mkl_info:
    No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
    customize MSVCCompiler
      libraries mkl_rt not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    blis_info:
      libraries blis not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    openblas_info:
      libraries openblas not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
    get_default_fcompiler: matching types: '['gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95', 'intelvem', 'intelem', 'flang']'
    customize GnuFCompiler
    Could not locate executable g77
    Could not locate executable f77
    customize IntelVisualFCompiler
    Could not locate executable ifort
    Could not locate executable ifl
    customize AbsoftFCompiler
    Could not locate executable f90
    customize CompaqVisualFCompiler
    Could not locate executable DF
    customize IntelItaniumVisualFCompiler
    Could not locate executable efl
    customize Gnu95FCompiler
    Could not locate executable gfortran
    Could not locate executable f95
    customize G95FCompiler
    Could not locate executable g95
    customize IntelEM64VisualFCompiler
    customize IntelEM64TFCompiler
    Could not locate executable efort
    Could not locate executable efc
    customize PGroupFlangCompiler
    Could not locate executable flang
    don't know how to compile Fortran code on platform 'nt'
      NOT AVAILABLE

    atlas_3_10_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries tatlas not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    atlas_3_10_blas_info:
      libraries satlas not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    atlas_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    atlas_blas_info:
      libraries f77blas,cblas,atlas not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    accelerate_info:
      NOT AVAILABLE

    C:\Users\User001\AppData\Local\Temp\pip-install-c07n3_wi\numpy\numpy\distutils\system_info.py:1914: UserWarning:
        Optimized (vendor) Blas libraries are not found.
        Falls back to netlib Blas library which has worse performance.
        A better performance should be easily gained by switching
        Blas library.
      if self._calc_info(blas):
    blas_info:
      libraries blas not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    C:\Users\User001\AppData\Local\Temp\pip-install-c07n3_wi\numpy\numpy\distutils\system_info.py:1914: UserWarning:
        Blas (http://www.netlib.org/blas/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [blas]) or by setting
        the BLAS environment variable.
      if self._calc_info(blas):
    blas_src_info:
      NOT AVAILABLE

    C:\Users\User001\AppData\Local\Temp\pip-install-c07n3_wi\numpy\numpy\distutils\system_info.py:1914: UserWarning:
        Blas (http://www.netlib.org/blas/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [blas_src]) or by setting
        the BLAS_SRC environment variable.
      if self._calc_info(blas):
      NOT AVAILABLE

    non-existing path in 'numpy\\distutils': 'site.cfg'
    lapack_opt_info:
    lapack_mkl_info:
      libraries mkl_rt not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    openblas_lapack_info:
      libraries openblas not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    openblas_clapack_info:
      libraries openblas,lapack not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    flame_info:
      libraries flame not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    atlas_3_10_threads_info:
    Setting PTATLAS=ATLAS
      libraries lapack_atlas not found in C:\Users\User001\appdata\local\programs\python\python39\lib
      libraries tatlas,tatlas not found in C:\Users\User001\appdata\local\programs\python\python39\lib
      libraries lapack_atlas not found in C:\
      libraries tatlas,tatlas not found in C:\
      libraries lapack_atlas not found in C:\Users\User001\appdata\local\programs\python\python39\libs
      libraries tatlas,tatlas not found in C:\Users\User001\appdata\local\programs\python\python39\libs
    
      NOT AVAILABLE

    atlas_3_10_info:
      libraries lapack_atlas not found in C:\Users\User001\appdata\local\programs\python\python39\lib
      libraries satlas,satlas not found in C:\Users\User001\appdata\local\programs\python\python39\lib
      libraries lapack_atlas not found in C:\
      libraries satlas,satlas not found in C:\
      libraries lapack_atlas not found in C:\Users\User001\appdata\local\programs\python\python39\libs
      libraries satlas,satlas not found in C:\Users\User001\appdata\local\programs\python\python39\libs
    
      NOT AVAILABLE

    atlas_threads_info:
    Setting PTATLAS=ATLAS
      libraries lapack_atlas not found in C:\Users\User001\appdata\local\programs\python\python39\lib
      libraries ptf77blas,ptcblas,atlas not found in C:\Users\User001\appdata\local\programs\python\python39\lib
      libraries lapack_atlas not found in C:\
      libraries ptf77blas,ptcblas,atlas not found in C:\
      libraries lapack_atlas not found in C:\Users\User001\appdata\local\programs\python\python39\libs
      libraries ptf77blas,ptcblas,atlas not found in C:\Users\User001\appdata\local\programs\python\python39\libs
    
      NOT AVAILABLE

    atlas_info:
      libraries lapack_atlas not found in C:\Users\User001\appdata\local\programs\python\python39\lib
      libraries f77blas,cblas,atlas not found in C:\Users\User001\appdata\local\programs\python\python39\lib
      libraries lapack_atlas not found in C:\
      libraries f77blas,cblas,atlas not found in C:\
      libraries lapack_atlas not found in C:\Users\User001\appdata\local\programs\python\python39\libs
      libraries f77blas,cblas,atlas not found in C:\Users\User001\appdata\local\programs\python\python39\libs
    
      NOT AVAILABLE

    lapack_info:
      libraries lapack not found in ['c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\lib', 'C:\\', 'c:\\users\\User001\\appdata\\local\\programs\\python\\python39\\libs']
      NOT AVAILABLE

    C:\Users\User001\AppData\Local\Temp\pip-install-c07n3_wi\numpy\numpy\distutils\system_info.py:1748: UserWarning:
        Lapack (http://www.netlib.org/lapack/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [lapack]) or by setting
        the LAPACK environment variable.
      return getattr(self, '_calc_info_{}'.format(name))()
    lapack_src_info:
      NOT AVAILABLE

    C:\Users\User001\AppData\Local\Temp\pip-install-c07n3_wi\numpy\numpy\distutils\system_info.py:1748: UserWarning:
        Lapack (http://www.netlib.org/lapack/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [lapack_src]) or by setting
        the LAPACK_SRC environment variable.
      return getattr(self, '_calc_info_{}'.format(name))()
      NOT AVAILABLE

    numpy_linalg_lapack_lite:
      FOUND:
        language = c
        define_macros = [('HAVE_BLAS_ILP64', None), ('BLAS_SYMBOL_SUFFIX', '64_')]

    C:\Users\User001\appdata\local\programs\python\python39\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'define_macros'
      warnings.warn(msg)
    running dist_info
    running build_src
    build_src
    building py_modules sources
    creating build
    creating build\src.win-amd64-3.9
    creating build\src.win-amd64-3.9\numpy
    creating build\src.win-amd64-3.9\numpy\distutils
    building library "npymath" sources
    error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\User001\appdata\local\programs\python\python39\python.exe' 'C:\Users\User001\appdata\local\programs\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\User001\AppData\Local\Temp\tmpmtdh020c' Check the logs for full command output.

這麼長的錯誤訊息, 重點在倒數第三行, 也就是第 210 行. 它叫我們去 MS 的網站 https://visualstudio.microsoft.com/downloads/ 下載並安裝 "Build Tools for Visual Studio"

但是當你依連結來到這一頁時, 可能會有點不知如何是好 (這一頁的資訊實在有點多, 尤其是第一次來的人...). 沒關係, 請向下滑, 一直到 "所有下載"... 並點開 "Visual Studio 2019 的工具"(註四).

下載 "Build Tools for Visual Studio"-1

下載 "Build Tools for Visual Studio"-1

最後一個下載項目就是 "Build Tools for Visual Studio"

下載 "Build Tools for Visual Studio"-2

下載 "Build Tools for Visual Studio"-2

但是現在這個連結下載下來的己經變成 Visual Studio 2019 的安裝程式 (Visual Studio Installer). 不過沒有關係, 我們依然可以只選擇第一項的 "C++ 建置工具" (或者可以 google —下 visualcppbuildtools_full.exeMS 下載 VS C++ 2015 版本的建置工具).

安裝好 "Build Tools for Visual Studio", 再重新安裝一次 numpy 就可以了.

不過由於這次 fmod() 的 bug, 所以抱歉, 這一次這樣子是解決不了問題的. (只能退版回去用 ver. 1.19.3)

註四: Build Tools for Visual Studio (即所謂的 msbuild) 只是 Visual Studio 的一部份, Visual Studio 要編譯程式時也是呼叫它 (MSBuild.exe) 來進行編譯的工作. 自 Visual Studio 2017 微軟開始提供單獨的安裝包 (就是我請大家下載的那一個). 其安裝程式和 Visual Studio 是共用的, 所以安裝時看到它帶出 Visual Studio 的安裝選項也不必太驚訝 (如果你已經安裝了 Visual Studio).

還有, 其實哪一個版本的 Visual Studio (2017, 2019, 2022...) 並不是很重要, 因為我們只是需要裡面的 "Build Tools for Visual Studio" (MS C++ compiler/linker). 而這一部份其實差異很小: VS2015 裡的 MSVC 版本是 v140, VS2017 裡的 MSVC 版本是 v141, VS2019 裡的 MSVC 版本是 v142 (VS2022 裡的 MSVC 版本是 v143). 同時, MS 說自 VS2015 版起, 保證了二進位相容性. 因此只要安裝新版本的工具, 連結時可以混用舊版本編譯出來的 obj, library. 可以免去整個重新編譯的麻煩.

解 jupyterlab-git 安裝失敗的 bug


加裝插件後 jupyter lab build 指令失敗的問題已經解決, 讀者不必再修改程式, 直接執行 pip install jupyterlab-git, jupyter lab build 這二行指令即可.2021/11/26

jupyterlab好用之處是, 它可以加裝 plugin. 透過 plugin, jupyterlab可以和 git 整合在一起.

不過這個 git 的 plugin 除了要另外安裝 git 之外, 我們還需要加裝 NodeJS 才能重建整合環境. 所以請先下載安裝 gitNodeJS (這二個軟體都有 Windows 安裝包, 安裝上相對相易, 在此就不多說了). 二個軟體都安裝妥當之後:

pip install jupyterlab-git
jupyter lab build

Windows 以外的平台這樣就可以使用了. Windows 平台呢? 那是一定會失敗. 問題出在 jupyterlabcommands.py 這一支程式少了一行(註五).

請找到 vLAB\Lib\site-packages\jupyterlab\commands.py 這一支 python 程式 (記得把 vLAB 換成你的虛擬環境名稱).

並使用文字編輯器在第 89 行插入一行encoding="UTF-8", 如下圖.

改好了, 就可以執行最後一行 jupyter lab build asset. 成功之後, Jupyterlab 的頁面如下圖.

註五: 這個 bug 已經有許多人報告了 (jupyterlab issues #8600, #9016, #9171...), 但就是不知道什麼時候才會釋出已經解決的版本. 新版已解決.

加裝其他 kernel (Julia, R, MATLAB, Octave...)


前面提到 jupyter 提供了包含 Julia, python, R...等多種程式語言共用的 REPL 核心, 但是要能夠使用我們還需要為其他程式語言加裝所謂的 kernel. 當然程式語言本身也要先安裝, 例如: R 語言一般是安裝 CRAN R-4.1.2 for Windows 再加上一個 IDE 環境 RStudio, 而使用 jupyter 則可以直接替代 RStudio 這套 IDE 環境.

github 上的這個連結可以查到目前有哪些語言有 jupyter kernel.

jupyter kernel 的安裝方法如下:

  1. 請先確定 shutdown jupyter 環境.
  2. 先安裝語言, 再安裝該語言的 jupyter kernel.
  3. 安裝完成後, 啟動 jupyter 即可使用.

一部份的 jupyter kernel 是可以直接安裝, 再重啟 jupyter 即可. 不過建議你按步就班來, 免得出錯了又要重來.

以下是 jupyter kernel 相關的指令, 可以用來協助你除錯:

  • 列出目前已經安裝的 kernel 及位置:
  • jupyter kernelspec list
    
  • 移除已經安裝的 kernel.
  • jupyter kernelspec uninstall <kernel_name>
    
  • 手動安裝的 kernel (如果你知道 kernelspec 的路徑).
  • jupyter kernelspec install [--user|--sys-prefix] --name <kernel_name> <prepared_kernel_dir>
    

下面介紹的是幾個我安裝過的 kernel:

  • MATLAB: 有些 Machine Learning 課程用的是 MATLAB 為主要語言而不是 python. jupyter 環境一樣可以支援 MATLAB. 在 jupyterlab 環境裡安裝 MATLAB jupyter kernel 的方法如下:
  • jupyter labextension install @jupyterlab/server-proxy
    

    如果你是 linux 環境下使用 jupyter notebook, 則可以改用以下指令:

    pip install jupyter-matlab-proxy
    

    有一點要注意的是, 這一個 MATLAB 的 jupyter kernel 不會出現在指令 jupyter kernelspec list 的清單中.

    此外, 最近還發現另一個叫 imatlab 的, 安裝方法是:

    pip install imatlab
    python -m imatlab install
    

    看起來好像比較簡單一點, 不過個人因為沒 MATLAB license 可用了, 所以也就沒有試一下. 各位就自己看著辦吧!

  • Octave: Octave 是 MATLAB 的替代品, 如果沒錢買 MATLAB 可以換用 Octave. Octave jupyter kernel 的安裝方法如下:
  • pip install octave_kernel
    
  • R: R 語言的 jupyter kernel 安裝方法比較麻煩一些, 如下:
    1. 先啟動 jupyter 環境所在的 venv (以下以 vJNB 為例). 請務必啟動虛擬環境, 因為我們要安裝到 sys.prefix 裡, 沒有啟動虛擬環境就會變成安裝到虛擬環境外的 global python 裡.
    2. D:\Works\jupyter>vJNB\Scripts\activate
      
    3. 進入 R console
    4. (vJNB) D:\Works\jupyter>d:\R-4.1.2\bin\R.exe
      
      R version 4.1.2 (2021-11-01) -- "Bird Hippie"
      Copyright (C) 2021 The R Foundation for Statistical Computing
      Platform: x86_64-w64-mingw32/x64 (64-bit)
      
      R 是自由軟體,不提供任何擔保。
      在某些條件下歡迎您將其散佈。
      用 'license()' 或 'licence()' 來獲得散佈的詳細條件。
      
      R 是個協作計劃,有許多人為之做出了貢獻。
      用 'contributors()' 來看詳細的情況以及
      用 'citation()' 會告訴您如何在出版品中正確地參照 R 或 R 套件。
      
      > 
    5. 在 R console 中執行指令 (橘紅色部份)
    6. > install.packages('IRkernel')
      ...安裝訊息 (略)
      package 'glue' successfully unpacked and MD5 sums checked
      package 'rlang' successfully unpacked and MD5 sums checked
      ...安裝訊息 (略)
      package 'digest' successfully unpacked and MD5 sums checked
      package 'IRkernel' successfully unpacked and MD5 sums checked
      
      The downloaded binary packages are in
              C:\Users\jackt\AppData\Local\Temp\Rtmp6BjZBZ\downloaded_packages
      > IRkernel::installspec(sys_prefix = TRUE)
      [InstallKernelSpec] Installed kernelspec ir in D:\Works\jupyter\vJNB\share\jupyter\kernels\ir
      > q()
      

    註六: 在 R console 中執行 IRkernel::installspec() 其實相當於在 cmd console 中執行指令 jupyter kernelspec install... 對應的動作其實就是把 R 語言的 kernelspec 目錄中的檔案 copy 到對應的目標位置上.

    • IRkernel::installspec():
      安裝到路徑 "%APPDATA%\jupyter\kernels\ir", 即使用者的家目錄下的 AppData\Roaming\jupyter\kernels\ir. 等同於指令:
      jupyter kernelspec install --name ir --user d:\R-4.1.2\library\IRkernel\kernelspec
      
    • IRkernel::installspec(user = FALSE):
      安裝到 C:\ProgramData\jupyter\kernels\ir. 等同於指令:
      jupyter kernelspec install --name ir d:\R-4.1.2\library\IRkernel\kernelspec
      
    • IRkernel::installspec(sys_prefix = TRUE):
      安裝到虛擬環境下的 share\jupyter\kernels\ir. 等同於指令:
      jupyter kernelspec install --name ir --sys-prefix d:\R-4.1.2\library\IRkernel\kernelspec
      
  • Julia: Julia 的 jupyter kernel 安裝步驟和 R 類似, 都有點麻煩. 方法如下:
    1. 進入 Julia console (Julia REPL)
    2. 在 Julia console 中執行指令:
    3. using Pkg
      Pkg.add("IJulia")
      
      Add IJulia to jupyterlab

      Juila: 安裝 "IJulia"

    IJulia 注意事項:

    • IJulia 目前只會優先安裝到環境變數 JUPYTER_DATA_DIR 所指定的目錄下的 kernels\julia-1.x, 沒有指定時安裝到路徑 "%APPDATA%\jupyter\kernels\julia-1.x" (即 使用者的家目錄下的 AppData\Roaming\jupyter\kernels\julia-1.x 子目錄裡).
    • 可以自己手動搬到虛擬環境中 (剪下目錄 julia-1.x, 貼到虛擬環境目錄中. 即在目錄 vJNB\share\jupyter\kernels 裡貼上), 但是請不要更動 julia-1.x 的目錄名. 千萬不要自己手動搬到虛擬環境中, 手動搬外觀看似成功, 但實際上卻無法成功執行 (主要是一些 Package 路徑不對).
    • Jupyterlab kernelspec

      Jupyterlab 各個 kernel 的位置.

    • 如果因為某些不知原因的操作失誤使得 Julia 在 jupyter kernelspec list 列表中不見了, 連使用 Pkg.rm("IJulia"); Pkg.add("IJulia") 指令移除後重裝也救不回來時, 可以改用以下指令:
    • using IJulia
      installkernel("Julia")

最後貼一張安裝了 jupyterlab-git, MATLAB proxy, octave kernel, R kernel 和 Julia kernel 的完成圖 (證明都是自己動手安裝過...).

Jupyterlab with Kernels

擴充完成後的 jupyterlab 外觀圖

arrow
arrow

    MagicJackTing 發表在 痞客邦 留言(2) 人氣()