jupyter | jupyter C++开发环境构建

慈云数据 2024-03-22 技术支持 63 0

搭建环境

按照 https://root.cern.ch/cling-build-instructions 官网的提示,手动编译Cling编译器,分别检查llvm,clang和cling:

mkdir /path/to/cling
cd /path/to/cling
git clone http://root.cern.ch/git/llvm.git
cd llvm
git checkout cling-patches
cd tools
git clone http://root.cern.ch/git/cling.git
git clone http://root.cern.ch/git/clang.git
cd clang
git checkout cling-patches
cd ../..
sudo mkdir /usr/local/cling
cd /path/to/cling
cd llvm
mkdir build
cd build
export CC=/usr/bin/gcc
export CXX=/usr/bin/g++
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/cling -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -j32
cmake --build . --target install -j8

查看cling kernel是否安装完成

# 继续上次目录
cd ../tools/cling/tools/Jupyter/kernel
tree
# 可以看到已经生成了很多的kernel

安装C++内核

安装C++内核前,请确保已经安装python3环境下已经安装ipython

sudo pip install ipython

重定向到带有setup.py文件的所在目录

# cd到kernel目录
#cd /path/to/cling/llvm/tools/cling/tools/Jupyter/kernel
sudo pip install -e .

安装你需要的C++内核版本,我这里安装C++14

jupyter kernelspec install --user ./cling-cpp14
# 系统环境配置
vim ~/.bashrc
# 添加
export PATH=$PATH:/usr/local/cling/bin

接着

# 激活系统环境
source ~/.bashrc
# 启动jupyter
jupyter notebook

测试一下,创建一个test_cpp.ipynb,kernel选择C++14

这样就大功告成了,可以愉快地在jupyter中进行cpp编程了。

 

微信扫一扫加客服

微信扫一扫加客服

点击启动AI问答
Draggable Icon