jupyter指定环境启动
-
背景
- 系统环境中安装有jupyter及相关库,因项目需要,新建了一个torch相关的虚拟环境并安装了对应的内容,
此时,想通过系统中的jupyter启动一个可以应用虚拟环境相关包的服务。 -
查看当前服务相关信息
import os, sys
print(sys.executable)
print(sys.version)
print(sys.version_info)
尝试1:只是在虚拟环境中启动jupyter
- source到虚拟环境中,直接jupyter notebook启动服务
- 得到结果如下,还是系统python,未成功

可能遇到的问题1
这种时候可能会出现服务启动成功,但无法通过网页访问的情况,开启端口权限就好。

尝试2:在jupyter中增加虚拟环境的核
lsvirtualenv
jupyter kernelspec list
pip install ipykernel
python -m ipykernel install --name my_evn01

- 成功了,得到结果如下

后续
其实不仅仅是增加虚拟环境到jupyter的kernel中,还可以增加其他的核进去,比如scala的核。这个的教程可以见我后面的文章。

|