问题1:Jupyter使用中,明明已经在环境中安装了包,但是import包时报错No module named 'torch' 或其他包名
原因是没有正确使用到conda建立的虚拟环境
jupyter中添加建立好的虚拟环境即可:
python -m ipykernel install --user --name AI_3.8 --display-name "Python AI_3.8"
查看kernel命令
jupyter kernelspec list
卸载指定的kernel命令(kernel_name为需要卸载的kernel名称)
jupyter kernelspec remove kernel_name
问题2:如何更改默认打开路径
刚安装jupyter默认目录是用户目录
Step1 生成配置文件
jupyter notebook --generate-config
Step2 使用vim打开该文件
vim .jupyter/jupyter_notebook_config.py
Step3 查找配置默认目录的位置
不要按i进入插入模式,输入/notebook.dir查找对应位置
Step4 删除改行前面的注释符号
Step5 修改路径为你需要的路径,然后退出保存
问题3 如何自动加载conda虚拟环境到jupyter内核
(base)$ conda install nb_conda_kernels
(base)$ conda create --name new-env
(base)$ conda activate new-env
(new-env)$ conda install ipykernel