2

I have been trying to install a Rust kernel for a Jupyter server inside a dedicated conda environment but I get errors.

Slighty adjusting steps from:
https://depth-first.com/articles/2020/09/21/interactive-rust-in-a-repl-and-jupyter-notebook-with-evcxr/

  1. conda create -n rusttest
  2. conda activate rusttest
  3. conda install -c conda-forge rust jupyterlab
  4. conda install -c anaconda cmake -y
  5. cargo install evcxr_jupyter
  6. Add $HOME/.cargo/bin to my PATH variable (export PATH)
  7. evcxr_jupyter --install (here I already see the kernel is installed outside the env)
  8. jupyter lab

The kernel is visible on the dashboard however when I try to start a notebook with it the connection fails and I get:

Error: Failed to find sysroot for Cargo.toml file /tmp/.tmpbZ0Pkw/Cargo.toml. Is rust-src installed?

I have tried manually:

jupyter kernelspec install {MY_PATH_DURING_PKG_INSTALLATION}/Jupyter/kernels/rust --sys-prefix

And I get:

[InstallKernelSpec] Installed kernelspec rust in {MY_PATH}/miniconda3/envs/rusttest/share/jupyter/kernels/rust

Which seems OK (inside the correct conda env) but the error persists.

Is there any way to add a working kernel just to this one jupyter server inside that env?
(I want Rust to be gone when I start jupyter lab from another conda env)

EDIT

After digging into this I think the first thing is to get rust-src installed inside that conda environment... I don't know how...

maciek
  • 1,807
  • 2
  • 18
  • 30

2 Answers2

2

Solved:

I needed to download https://static.rust-lang.org/dist/2022-05-19/rust-src-1.61.0.tar.gz manually and extract it under the env dir such that XXX/miniconda3/envs/rusttest/lib/rustlib/src/rust exists.

maciek
  • 1,807
  • 2
  • 18
  • 30
  • Thank you, could you please put link for other distributions beside 1.61? – Medhat Feb 19 '23 at 02:23
  • try looking at their .toml files by version such as http://static.rust-lang.org/dist/channel-rust-1.13.0.toml or http://static.rust-lang.org/dist/channel-rust-1.67.1.toml etc. (ref: https://github.com/rust-lang/rust-forge/issues/215#issuecomment-488328424) – Alex L Apr 12 '23 at 21:53
0

I had installed rust (which installs rustc and cargo) like so:

conda activate my_env
conda install rust=1.67.1 -c conda-forge

you may be able to just install rust-src as such (but I haven't tried yet) - but it is a package https://anaconda.org/conda-forge/rust-src/files:

conda activate my_env
conda install rust-src=1.67.1 -c conda-forge

Alternatively, a more programatic take on @maciek's answer:

try looking at their .toml files by version such as http://static.rust-lang.org/dist/channel-rust-1.13.0.toml or http://static.rust-lang.org/dist/channel-rust-1.67.1.toml etc. and find the rust-src download link (ref: https://github.com/rust-lang/rust-forge/issues/215#issuecomment-488328424)

We can do this part programatically too:

brew tap 4rbor/tq && brew install tq
wget http://static.rust-lang.org/dist/channel-rust-1.67.1.toml
RUST_SRC_URL=$(tq -f channel-rust-1.67.1.toml 'pkg.rust-src.target.*.url')

Then:

cd ~/miniconda/envs/my_env/
wget -c $RUST_SRC_URL -O - | tar -xz
cp -r rust-src-1.67.1/rust-src/lib/rustlib lib
Alex L
  • 4,168
  • 1
  • 9
  • 24