skip to Main Content

I have installed Anaconda 3 and VS Code on Windows 10. I am interested in running Rust in a notebook, and I found CodeBook which seemed to fit the bill. I installed Rust using conda in an environment conda create -n rust_env -c conda-forge rust, and then installed the rust-analyzer extension in VS Code and created a markup document which I opened in CodeBook.

However, when I try to run a cell, I find that rust-analyzer has scanned 0 of 0 roots and "failed to load workspace ‘cargo’ – program not found".

If I activate the rustenv using conda in the terminal I can run cargo --version, but it seems that CodeBook is not running Rust in the right environment. Any idea how I can set this?

I cannot find any help in the rust-analyzer manual:
https://rust-analyzer.github.io/manual.html

VS Code showing conda environment in terminal

First errors on start-up

"The Rust Analyzer Language Server server crashed 5 times in the last 3 minutes."

Analyzer client references non-existent directory

UPDATE: I have added the rust executables to the path:
C:ProgramDataAnaconda3envsrustenvLibrarybin

Now there are server errors…

[Info  - 2:10:43 pm] Connection to server got closed. Server will restart.
[Error - 2:10:43 pm] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 2:10:43 pm] Rust Analyzer Language Server client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 2:10:43 pm] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 2:10:45 pm] Connection to server got closed. Server will restart.
[Error - 2:10:45 pm] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 2:10:45 pm] Rust Analyzer Language Server client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 2:10:45 pm] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 2:10:45 pm] The Rust Analyzer Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

I don’t understand what this means…

2

Answers


  1. My experience is that, unfortuneately, VS Code does not work nice with conda for rust. You will have to change settings in multiple places and I actually never got it to work myself.

    It is better to install rust on your system without conda, and then everything in VS Code works out of the box.

    • In your case, on Windows, you would install with rustup-init.exe

    • For those on Linux/Mac, you would install with rustup

    Login or Signup to reply.
  2. I recently got rust and rust-analyzer working in a conda environment, it was a bit of a pain, so up to you if you think it is worth it or not.

    I wrote about it here: https://github.com/rust-lang/rust-analyzer/issues/14477#issuecomment-1506098692

    And copying the info here:

    It took quite a few steps. I have not determined concretely if all of these are needed but certainly most of them are:

    • add conda env to path (for me in .zshrc) and/or just conda activate zzz in the same file
    • downloading/installing rust-src into my conda env, which is not included as part of the conda rust install (see: https://stackoverflow.com/a/76000140/9792594)
    • add export RUST_SRC_PATH="/Users/xxx/miniconda/envs/zzz/lib/librust/src/rust/src" also to .zshrc

    for reference I have:

    • MacOS 13.3.1 (22E261)
    • conda=23.1.0
    • rust=1.67.1
    • cargo --version = cargo 1.67.1 (8ecd4f20a 2023-01-10)
    • rustc --version = rustc 1.67.1 (d5a82bbd2 2023-02-07)
    • ~/.vscode/extensions/rust-lang.rust-analyzer-0.3.1472-darwin-arm64/server/rust-analyzer --version = rust-analyzer 0.3.1472-standalone (01120f121 2023-04-07)
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search