anaconda虚拟环境运行jupyter

anaconda虚拟环境运行jupyter

ipykernel安装配置

jupyter notebook运行需要的kernel和conda创建的虚拟环境并不能完全互通。
利用conda创建了虚拟环境,但是启动jupyter notebook之后却找不到虚拟环境。
实际上是由于在虚拟环境下缺少kernel.json文件。解决方案如下:

首先安装ipykernel:

conda install ipykernel

在虚拟环境下创建kernel文件:

conda install -n 环境名称 ipykernel

将环境写入notebook的kernel中:

python -m ipykernel install --user --name 环境名称 --display-name "你想为kernel添加的名称"

如果经常需要用jupyter notebook,那么最好在创建虚拟环境的时候便安装好ipykernel:

conda create -n 环境名称 python=3.5 ipykernel

启动jupyter

进入ipython或python环境

ipython
python

在python或ipython环境下输入:

from notebook.auth import passwd
passwd()

这时会提示你输入密码:

Enter password:
Verify password:

输入完成后,会输出一个字符串,形如 ’sha1:9e7a5c5e0a29:8cbdvsv2344d141c92beab1c5bc6e9avsdvdsvsv’,将其复制保存
退出输入:

exit()

配置jupyter notebook

jupyter notebook --generate-config

会产生文件:

home/你的文件名/.jupyter/jupyter_notebook_config.py

进入配置文件jupyter_notebook_config.py:

vim ~/.jupyter/jupyter_notebook_config.py

会出现如下情形:

c.NotebookApp.ip= '*'  #允许访问此服务器的 IP,*表示任意IP
c.NotebookApp.password = u'sha1:9e7a5c5e0a29:8cbdvsv2344d141c92beab1c5bc6e9avsdvdsvsv' #之前生成的密码 hash 字串
c.NotebookApp.open_browser = False # 运行时不打开本机浏览器
c.NotebookApp.port = 12035 # 使用的端口,随意设置

修改结束后,保存并退出

打开jupyter notebook

# jupyter notebook

[W 11:59:49.343 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[C 11:59:49.347 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.
(rcnn) root@os-Super-Server:/AI/soft/Jupyter# jupyter notebook --allow-root
[W 11:59:58.874 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 11:59:58.879 NotebookApp] Serving notebooks from local directory: /AI/soft/Jupyter
[I 11:59:58.879 NotebookApp] Jupyter Notebook 6.4.0 is running at:
[I 11:59:58.879 NotebookApp] http://os-Super-Server:9999/
[I 11:59:58.879 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 12:00:11.470 NotebookApp] 302 GET / (10.78.8.69) 0.440000ms
[I 12:00:11.474 NotebookApp] 302 GET /tree? (10.78.8.69) 0.680000ms
[I 12:00:14.042 NotebookApp] 302 POST /login?next=%2Ftree%3F (10.78.8.69) 53.450000ms

在网页中输入地址,os-Super-Server是指你实际的运行juypter的ip地址

 http://os-Super-Server:9999/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值