0%

【Rust】在jupyter notebook中使用Rust

在jupyter notebook中是否也可以像python那样使用呢? 答案是可以的。现在来记录一下配置步骤。

使用EvCxR作为jupyter notebook内核

安装

  1. 安装jupyter notebook或者jupyter lab

  2. 安装CMake,在安装EvCxR编译时会使用到。

  3. 安装EvCxR

    1
    2
    cargo install evcxr_jupyter
    evcxr_jupyter --install

问题

安装过程中,原来rust选择的是gnu的工具链编译,但在编译libzmq时会报错,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
D:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\G__~1.EXE   -std=gnu++11 -Wno-tautological-constant-compare  -o CMakeFiles\cmTC_57766.dir\CheckSymbolExists.cxx.obj -c E:\Tmp\libzmq-4.3.3\build\CMakeFiles\CMakeTmp\CheckSymbolExists.cxx

E:\Tmp\libzmq-4.3.3\build\CMakeFiles\CMakeTmp\CheckSymbolExists.cxx: In function 'int main(int, char**)':
E:\Tmp\libzmq-4.3.3\build\CMakeFiles\CMakeTmp\CheckSymbolExists.cxx:8:19: error: 'strlcpy' was not declared in this scope
return ((int*)(&strlcpy))[argc];
^~~~~~~
E:\Tmp\libzmq-4.3.3\build\CMakeFiles\CMakeTmp\CheckSymbolExists.cxx:8:19: note: suggested alternative: 'strncpy'
return ((int*)(&strlcpy))[argc];
^~~~~~~
strncpy
At global scope:
cc1plus.exe: warning: unrecognized command line option '-Wno-tautological-constant-compare'
mingw32-make.exe[1]: *** [CMakeFiles\cmTC_57766.dir\build.make:84: CMakeFiles/cmTC_57766.dir/CheckSymbolExists.cxx.obj] Error 1

mingw32-make.exe[1]: Leaving directory 'E:/Tmp/libzmq-4.3.3/build/CMakeFiles/CMakeTmp'

mingw32-make.exe: *** [Makefile:139: cmTC_57766/fast] Error 2



File E:/Tmp/libzmq-4.3.3/build/CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <string.h>

int main(int argc, char** argv)
{
(void)argv;
#ifndef strlcpy
return ((int*)(&strlcpy))[argc];
#else
(void)argc;
return 0;
#endif
}

尝试手动编译libzmq, 但无论4.3.3或4.3.2版本都无法成功。 具体原因从issue里也没有太多参考意义。后来从EvCxR issue 53中得到些启发,将rust的工具链换回msvc工具链。重新安装EvCxR,成功。

测试

# 参考

  1. EvCxR Jupyter Kernel