windows下使用 Jupyter notebook 运行 C++

windows下使用 Jupyter notebook 运行 C++

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就可以编写并运行代码了


分享到:


相關文章: