Rust交互式编程环境Jupyter Lab搭建

  • windows 11
  • wsl2
  • Ubuntu 24.04.1 LTS Installer.exe
  • rust-1.88.0-x86_64-unknown-linux-gnu.tar.xz
  • evcxr_jupyter-v0.20.0-x86_64-unknown-linux-gnu.tar.gz
  • Miniconda3-py312_25.1.1-2-Linux-x86_64.sh

/etc/apt/sources.list配置镜像源(最好先删除sources.list.d的官方源在apt update)

deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
 
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
 
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
 
# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
 
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse

设置默认wsl子系统为Ubuntu24.04

wsl --set-default Ubuntu-24.04

安装miniconda

chmod +x Miniconda3-py312_25.1.1-2-Linux-x86_64.sh
sh ./Miniconda3-py312_25.1.1-2-Linux-x86_64.sh

添加conda环境变量到.bashrc,并source .bashrc更新

# .bashrc里最末添加
# cmd里面wsl启动默认Ubuntu24.04时切到根目录
cd ~
export PATH="~/miniconda3/bin:$PATH"
# 启动wsl时自动切到下一步创建的虚拟环境
conda activate rustenv

创建conda虚拟环境

conda init
conda create -n rustenv python=3.12
conda activate rustenv


安装Jupyter lab

conda install -c conda-forge jupyterlab

或者使用国内源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main jupyterlab

完全解压到根路径然后安装rust

sh ./rust-1.88.0-x86_64-unknown-linux-gnu/install.sh

添加cargo环境变量到.bashrc

export PATH="~/.cargo/bin:$PATH"

完全解压并安装evcxr_jupyter

evcxr_jupyter --install

运行jupyter lab并选择rust后台

jupyter lab --allow-root

如果rust kernel起不来,尝试安装cc环境

apt install build-essential

pip安装的清华源

export PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple

效果

补充(cargo的国内源,不一定有用,最方便的还是下载离线包安装)

------------------------------

由于国内拉取 crates.io 以及安装 Rust 会面临流量出境不稳定的问题,我们提供了一个国内镜像代理以帮助国内 Rust 生态发展,欢迎大家使用。

配置说明

步骤一:设置 Rustup 镜像, 修改配置 ~/.zshrc or ~/.bashrc

export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"

步骤二:安装 Rust(请先完成步骤一的环境变量导入并 source rc 文件或重启终端生效)

curl --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh

步骤三:设置 crates.io 镜像, 修改配置 ~/.cargo/config,已支持git协议和sparse协议,>=1.68 版本建议使用 sparse-index,速度更快。

sparse

rsproxy

[source.crates-io]
replace-with = 'rsproxy-sparse'
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true

------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值