运用miniconda环境,vscode运行并切换jupyter内核
RedSun_bot
编辑于 2023年09月11日 07:11

# 安装miniconda3,并集成到powershell中

```powershell

scoop install miniconda3

conda init powershell

```

# 在base环境中安装jupyter

```powershell

conda install jupyter notebook

```

# conda中新建另一个环境 <your_env>

```powershell

conda create -n <your_env>

```

# 在新的环境中安装ipykernel

```powershell

conda activate <your_env>

conda install ipykernel

```

# 切换回base环境,添加<your_env>内核

```powershell

python -m ipykernel install --user  --name <your_env> --display-name "<your_env>&#​34;

```

# 自动添加的内核路径缺少了环境目录位置,手动修改

```powershell

jupyter kernelspec list

```

> Available kernels:

> base        C:\Users\RedSun\AppData\Roaming\jupyter\kernels\base

>  <your_env>   C:\Users\RedSun\AppData\Roaming\jupyter\kernels\<your_env>

> python3    C:\Users\RedSun\scoop\apps\miniconda3\current\share\jupyter\kernels\python3

``` powershell

open C:\Users\RedSun\AppData\Roaming\jupyter\kernels\<your_env>

code kernel.json

```

# 修改路径

    "C:\\Users\\RedSun\\scoop\\apps\\miniconda3\\current\\python.exe",

==>

(具体路径视自己安装的位置为准)

    "C:\\Users\\RedSun\\scoop\\apps\\miniconda3\\current\\envs\\<your_env>\\python.exe",

# 重新启动jupyternotebook

> 若内核仍无法启动,尝试更新ipykernel包

```powershell

conda activate <your_env>

pip install -U ipykernel

```