在Python虚拟环境下开启jupyter notebook

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_26919935/article/details/83505935

安装并配置

第一步:安装Jupyter Notebook

pip install jupyter

第二步:进入你的 Virtualenv里 (我是的venv3)

source venv3/bin/activite

第三步:使用清华镜像安装 IPykernel,比较快

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ipykernel

第四步:将你的 Virtualenv 加入IPykernel里

python -m ipykernel install --user --name=venv3 

第五步:打开Jupyter

jupyter notebook

报错以及处理

报错1:

[W 00:19:00.741 NotebookApp] No web browser found: could not locate runnable browser.
处理方式:

ipython
 
from IPython.lib import passwd
passwd() #得到加密后的hash
exit
jupyter notebook --generate-config
vim ~/.jupyter/jupyter_notebook_config.py
 
c.NotebookApp.ip = '*'
c.NotebookApp.allow_root = True
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.password = u'sha1:...' #输入上面加密后得到的密文

报错2

Refusing to serve hidden directory, via 404 Error
如果成功在浏览器连接上服务器,但是登录输入密码后出现了404 You are requesting a page that does not exist!:
处理方式:在配置文件里面加上ipython文件的的保存路径就可以了(最后一行)

vim ~/.jupyter/jupyter_notebook_config.py
 
c.NotebookApp.ip = '*'
c.NotebookApp.allow_root = True
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.password = u'sha1:...' #输入上面加密后得到的密文
c.NotebookApp.notebook_dir = '/path/to/your/hidden/directory/'

报错3:登陆失败,则有可能是服务器防火墙设置的问题,此时最简单的方法是在本地建立一个ssh通道:

在本地终端中输入ssh username@address_of_remote -L127.0.0.1:1234:127.0.0.1:8888
此处的8888是指远程服务器jupyter登录的端口
便可以在localhost:1234直接访问远程的jupyter了。

报错4:

KeyError: 'allow_remote_access'

During handling of the above exception, another exception occurred:
...
Traceback (most recent call last):
  File "/home/yujwang/kou/venv3.5/lib/python3.5/site-packages/notebook/notebookapp.py", line 869, in _default_allow_remote
    addr = ipaddress.ip_address(self.ip)
  File "/usr/lib/python3.5/ipaddress.py", line 54, in ip_address
    address)
ValueError: '' does not appear to be an IPv4 or IPv6 address

During handling of the above exception, another exception occurred:
...
socket.gaierror: [Errno -2] Name or service not known

在配置文件中加这样一行:

c.NotebookApp.allow_remote_access = True
展开阅读全文

没有更多推荐了,返回首页