Ubuntu配置
Ubuntu由ssh遠程訪問jupyter notebook
1. Jupyter-notebook configuration file
jupyter notebook --generate-config
Note: 會有以下配置文件生成的提醒:
Writing default config to: /home/computer_name/.jupyter/jupyter_notebook_config.
2. Generate password
使用python
,遠程電腦裏有ipython可以直接輸入ipython
$ python
from notebook.auth import passwd
passwd()
# 輸入完後會出現以下輸入密碼,該密碼爲遠程登錄jupyter密碼
Enter password:******
Verify password:******
# 下面爲配置文件的密文
輸出爲: 'sha1:cd723d3e4b0afg34hasrsf65yr453t32hj456d2627fb'
3. Modify configuration file
用vim或者gedit, 修改第一步生成的配置文件:
vim ~/.jupyter/jupyter_notebook_config.py
修改如下:
# *號表示任何的IP地址都可以訪問
c.NotebookApp.ip= '*' #204 line
# 前面第一步生成的密文
c.NotebookApp.password = u'sha1:cd723d3e4b0afg34hasrsf65yr453t32hj456d2627fb' #267 line
# 表示在打開jupyter的時候不會自動打開遠程的瀏覽器
c.NotebookApp.open_browser = False #276 line
# 這裏可以任意定義一個端口進行連接需要
c.NotebookApp.port = 9999 #288 line
以上行數爲修改之前的行數。
Note: 這裏打開以後所有的配置是被註釋掉的, 所以先複製上面的配置, 然後在另起一行進行修改.如下:
# c.NotebookApp.ip= 'hostname'
c.NotebookApp.ip= '*'
4. Launch jupyter-notebook
對不同python環境下的jupyter不熟悉的可以查看我另外一篇的最後一節 Link
1.在遠程電腦上的terminal中輸入jupyter-notebook
, 然後會出現一個警告, 這個沒關係, 記住之前設置密文的密碼就行.
[W 17:28:47.794 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
2.root 用戶使用
jupyter notebook --allow-root
3.後臺執行
nohup jupyter notebook --allow-root &
5. Remote login
在自己的電腦上, 可以直接從本地瀏覽器直接訪問http://address_of_remote:8888就可以看到jupyter的登陸界面.
比如: 遠程電腦的ip地址是: 127.0.0.1
你設置的端口號爲: 9999
那麼瀏覽器輸入: 127.0.0.1:9999 即可.
可以看到如下界面, 然後輸入第一步設置的密碼即可登錄到遠程電腦的home界面.
之後只需要遠程使用輕薄本, 來使用高性能臺式機爲自己的程序進行測試.
6. Problem
以上設置,測試過沒有問題的,但是最近遠程電腦重裝了以後,按照以上步驟出現的一些錯誤
~$ jupyter-notebook
Traceback (most recent call last):
File "/home/zzl/anaconda3/lib/python3.6/site-packages/traitlets/traitlets.py", line 528, in get
value = obj._trait_values[self.name]
KeyError: 'allow_remote_access'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/zzl/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 864, in _default_allow_remote
addr = ipaddress.ip_address(self.ip)
File "/home/zzl/anaconda3/lib/python3.6/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:
Traceback (most recent call last):
File "/home/zzl/anaconda3/bin/jupyter-notebook", line 11, in <module>
sys.exit(main())
File "/home/zzl/anaconda3/lib/python3.6/site-packages/jupyter_core/application.py", line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/home/zzl/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/home/zzl/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/home/zzl/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 1628, in initialize
self.init_webapp()
File "/home/zzl/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 1378, in init_webapp
self.jinja_environment_options,
File "/home/zzl/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 159, in __init__
default_url, settings_overrides, jinja_env_options)
File "/home/zzl/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 252, in init_settings
allow_remote_access=jupyter_app.allow_remote_access,
File "/home/zzl/anaconda3/lib/python3.6/site-packages/traitlets/traitlets.py", line 556, in __get__
return self.get(obj, cls)
File "/home/zzl/anaconda3/lib/python3.6/site-packages/traitlets/traitlets.py", line 535, in get
value = self._validate(obj, dynamic_default())
File "/home/zzl/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 867, in _default_allow_remote
for info in socket.getaddrinfo(self.ip, self.port, 0, socket.SOCK_STREAM):
File "/home/zzl/anaconda3/lib/python3.6/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname
可以看到最後錯誤顯示是hostname有問題,也就是這個這個出了問題:
# c.NotebookApp.ip= 'hostname'
c.NotebookApp.ip= '*'
原來的給任意的ip地址'*'
不合適,這裏修改爲遠程電腦的ip地址
。
c.NotebookApp.ip= 'your_remote_ip'