解决jupyter下载好了库,但是无法使用的问题。以及补充jupyter如何下载新的库。

文章目录

    • 出现原因
      • 验证
    • 解决步骤
    • 补充
      • 国内常用镜像源

出现原因

出现这个问题的主要原因是,jupyter的内核(或者说他使用的Python环境)与下载库的环境不一样,解决办法就是更改kernel。换句话说就是将jupyter下载库的环境加入到内核环境中。

验证

1.命令行输入jupyter kernelspec list,可以查看现在jupyter拥有的python环境
解决jupyter下载好了库,但是无法使用的问题。以及补充jupyter如何下载新的库。_第1张图片
2.conda env list,查看目前jupyter使用的下载库的环境
解决jupyter下载好了库,但是无法使用的问题。以及补充jupyter如何下载新的库。_第2张图片
如果你的这个环境不在1的kernelspec list中,那么就可以跟着往下做。

解决步骤

1.命令行activate base,激活虚拟环境

2.pip install ipykernel -i https://pypi.tuna.tsinghua.edu.cn.com/simple,安装ipykernel

3.将jupyter使用的Python环境引入到Jupyter内核中。
python -m ipykernel install --user --name base --display-name "conda_env_base"
其中–name后的base替换为出现问题-验证2中的conda环境映射名e.g.我的为base。
–deplay-name后可以替换为任何一个名字e.g.我的为conda_env_base。
整个过程可以看成是建立一个新的映射关系,让jupyter内核能够使用它下载库的环境。

4.重启jupyter,打开jupyter notebook更换环境

解决jupyter下载好了库,但是无法使用的问题。以及补充jupyter如何下载新的库。_第3张图片

补充

如果在jupter中下载新的库
1.简单点
!pip install module_name
2.嫌慢,加上源头
!pip install moudle_name -i 国内常用镜像源
e.g. !pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple

国内常用镜像源

清华大学: https://pypi.tuna.tsinghua.edu.cn/simple
阿里云: https://mirrors.aliyun.com/pypi/simple
中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple
豆瓣: http://pypi.douban.com/simple
中国科学技术大学: http://pypi.mirrors.ustc.edu.cn/simple
华中理工大学:http://pypi.hustunique.com/simple
山东理工大学:http://pypi.sdutlinux.org/simple

你可能感兴趣的:(jupyter,python)