1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rust を Jupyter で動かす(WSL+VSCode)

Last updated at Posted at 2025-04-10

前提

  • Windows11
  • WSL および VSCode をインストール済み
  • Rust は未インストール

本記事の手順により下記の画像のような構築が構築される.
image.png

Rust のインストール

  1. WSL 内で下記のコマンドを実行し,確認画面で Enter で Rust をインストールする
    $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    初期設定では Rust に関連するツールが ~/.cargo/bin にインストールされる.
  2. ~/.cargo/bin を PATH に追加する(または WSL を再起動する)
    $ source ~/.cargo/env
    
  3. Rust がインストールされていることを確認する
    $ rustc --version
    $ cargo --version
    
  4. gcc コンパイラをインストールする(Rust のコンパイルに必要)
    $ sudo apt install build-essential
    
    ※ gcc コンパイラがインストールされていないと,Rust のコンパイル時に下記のようなエラーが発生する.
    error: linker `cc` not found
    

参考

Jupyter で Rust を使えるようにする

  1. evcxr_jupyter をインストールする
    $ cargo install evcxr_jupyter
    
    cargo は Rust のパッケージ管理ツール(Python の pip のようなもの?)で,evcxr_jupyter は Rust 用の Jupyter Kernel です.私の環境ではインストールに5分程度かかりました.
  2. evcxr_jupyterJupyter に登録する
    $ evcxr_jupyter --install
    
  3. 適当なディレクトリを VSCode + WSL で開く
    $ mkdir ./rust-jupyter-test
    $ code ./rust-jupyter-test
    
  4. VSCode の拡張機能 Jupyter をインストールする
    image.png
  5. 拡張子が ipynb の適当な名前のファイルを作成する
    image.png
  6. ipynb ファイルを開き,Rust のカーネルを設定する
    image.png
    image.png
    image.png
  7. コードを実行
    image.png

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?