![windows下使用 Jupyter notebook 運行 C++](http://p2.ttnews.xyz/loading.gif)
1. Windows下安裝Linux子系統
- 由於 C++ kernel 僅支持Linux和macOS,故需要在Windows下安裝Linux子系統
- 安裝教程如下:
參考:https://blog.csdn.net/qq_20084101/article/details/82316263
2. Linux子系統中安裝anaconda
- 本人使用的是基於python3.6的anaconda3
- 安裝anaconda,使用清華鏡像源安裝更快
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.2.0-Linux-x86_64.sh
bash Anaconda3-5.2.0-Linux-x86_64.sh
3. 使用anaconda安裝支持c++的jupyter
- 進入 anaconda
source ~/anaconda3/bin/activate root
- 創建新的虛擬環境,命名為cling
conda create -n cling
- 切換到新創建的虛擬環境
conda activate cling
- 切換默認鏡像源加速安裝
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/freeconda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainconda config --set show_channel_urls yes
- 安裝jupyter notebook
conda install jupyter notebook此處很重要 :本人安裝了很多次xeus-cling都因為下載速度太慢而以失敗告終,後來發現是因為安裝xeus-cling時,我們想通過指定channel加快訪問速度時,conda反而會優先訪問默認源而非鏡像。
- 我們可以通過 ++conda config --show++ 看到 默認情況下的 ++channel_alias++ 值是 ++https://conda.anaconda.org/++
- 替換默認鏡像源
conda config --set channel_alias https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- 繼續使用conda-forge鏡像channel安裝xeus-cling
conda install xeus-cling -c conda-forge
- 檢查是否成功安裝了kernel
jupyter kernelspec list
- 正確安裝,會顯示以下四個kernel:
python3 /home/soleil/anaconda3/envs/cling/share/jupyter/kernels/python3 xcpp11 /home/soleil/anaconda3/envs/cling/share/jupyter/kernels/xcpp11 xcpp14 /home/soleil/anaconda3/envs/cling/share/jupyter/kernels/xcpp14 xcpp17 /home/soleil/anaconda3/envs/cling/share/jupyter/kernels/xcpp17
- 然後我們就可以運行jupyter notebook了
jupyter notebook新建new下拉菜單中選擇C++11就可以編寫並運行代碼了
閱讀更多 StriveBen 的文章