轉(zhuǎn)載自在服務(wù)器上配置jupyter, 遠程登錄
1.安裝與配置
第一步:安裝jupyter
參考:Ubuntu 安裝 Anaconda3 詳細步驟
或者可以使用:
pip3 install jupyter (此處使用的是python3)
第二步:生成配置文件jupyter notebook --generate-config
第三步:生成密鑰 打開python3 ,然后輸入
1. from notebook.auth import passwd
2. passwd()
3. 此時會讓你兩次輸入密碼,然后就會生成秘鑰
4. ************
修改配置文件
sudo vi ~/.jupyter/jupyter_notebook_config.py
大約在200行的位置始藕,找到下面配置
1. c.NotebookApp.ip='*' # 就是設(shè)置所有ip皆可訪問
1. c.NotebookApp.ip='0.0.0.0'
# "start of jupyter notebook server on ip adress '0.0.0.0' instead of default '*' which is no longer supported this is probably needed only on a temporary basis see also
https://github.com/jupyter/docker-stacks/issues/718
https://github.com/ageron/handson-ml/pull/317/commits")
2. c.NotebookApp.password = u'sha:ce... # 剛才復(fù)制的那個密文'
3. c.NotebookApp.open_browser = False # 禁止自動打開瀏覽器
4. c.NotebookApp.port =8888 #隨便指定一個端口
第四步:配置一下路由器的端口轉(zhuǎn)發(fā),
第五步:在服務(wù)器端啟動 jupyter notebook
第六步:本地地址欄輸入服務(wù)器ip:8888 就OK了
2.打開 Jupyter Notebook
打開 notebook 的方法非常簡單湿酸,只需在終端輸入
ipython notebook
3.退出
在ubuntu終端運行jupyter notebook后打開了jupyter的網(wǎng)頁,在關(guān)閉jupyter的網(wǎng)頁后如何在ubuntu終端退出jupyter notebook重新進入命令輸入行呢灭美?
同時按下ctrl和C鍵推溃,然后按照下面終端界面提示操作就可以了。
pip查看已安裝的包
# pip show --files SomePackage
Name: SomePackage
Version: 1.0
Location: /my/env/lib/pythonx.x/site-packages
Files:
../somepackage/__init__.py
[...]
4.安裝python2 kernal
sudo python2 -m pip install --user --ignore-installed python-dateutil ipykernel
jupyter kernel查看內(nèi)核
jupyter kernelspec list
卸載內(nèi)核
jupyter kernelspec remove kernelname
5. ubuntu 中jupyter notebook python2&3 并存使用
在終端輸入
$python2 -m pip install ipykernel
$python2 -m ipykernel install --user
$python3 -m pip install ipykernel
$python3 -m ipykernel install --user
----------------------
Kernels for Python 2 and 3
出現(xiàn)問題:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py", line 15, in <module>
from ipykernel import kernelapp as app
File "/usr/local/lib/python2.7/dist-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/usr/local/lib/python2.7/dist-packages/ipykernel/connect.py", line 14, in <module>
from IPython.paths import get_ipython_dir
ImportError: No module named paths
solution
這是由于系統(tǒng)自帶ipython版本與jupyter沖突届腐。
This is because of version conflict of ipython installed by apt-get package manager and ipython by pip:
so uninstall all versions of ipython from apt-get as follows:
sudo apt-get remove ipython ipython-notebook ipython-notebook-common
also remove from pip: both jupyter and ipython
sudo pip uninstall jupyter
sudo pip uninstall ipython
As ipython is part of jupyter, so just reinstall jupyter
sudo pip install jupyter
This should help!!!
附注:使用Anaconda管理不同版本
The idea here is to install multiple ipython
kernels. Here are instructions for anaconda. If you are not using anaconda, I recently added instructions using pure virtualenvs.
Anaconda 4.1.0
Since version 4.1.0, anaconda includes a special package nb_conda_kernels
that detects conda environments with notebook kernels and automatically registers them. This makes using a new python version as easy as creating new conda environments:
conda create -n py27 python=2.7 ipykernel
conda create -n py36 python=3.6 ipykernel
After a restart of jupyter notebook, the new kernels are available over the graphical interface. Please note that new packages have to be explicitly installed into the new enviroments. The Managing environments section in conda's docs provides further information.
Manually registering kernels
Users who do not want to use nb_conda_kernels
or still use older versions of anaconda can use the following steps to manually register ipython kernels.
configure the python2.7
environment:
conda create -n py27 python=2.7
source activate py27
conda install notebook ipykernel
ipython kernel install --user
configure the python3.6
environment:
conda create -n py36 python=3.6
source activate py36
conda install notebook ipykernel
ipython kernel install --user
After that you should be able to choose between python2
and python3
when creating a new notebook in the interface.
Additionally you can pass the --name
and --display-name
options to ipython kernel install
if you want to change the names of your kernels. See ipython kernel install --help
for more informations.
6. Jupyter使用
兩種模式
Command mode 和 Edit mode美莫。 在一個cell中页眯,按下Enter,進入Edit模式,按下Esc,進入Command 模式
運行當(dāng)前cell厢呵,并移動到下一個Cell
在一個cell中(在command模式下), Shift + Enter
創(chuàng)建Cell
在一個cell中(在command模式下)
1\. 按下 a ,即可在這個cell之前創(chuàng)建一個新的cell窝撵;
2\. 按下 b,即可在這個cell之后創(chuàng)建一個新的cell;
Cell中 Code 和 Markdown的切換
在一個cell中(在command模式下)
1\. 按下 y, 進入Code;
2\. 按下m, 進入Markdown;
顯示Cell中的行數(shù)
在一個cell中(在command模式下),按下 l
刪除Cell
在一個cell中(在command模式下), 按兩次 d
保存Notebook
在一個cell中(在command模式下), 按下 s
啟動命令面板
在一個cell中(在command模式下), 按下 Ctrl + Shift + P
界面中的小鍵盤也可以啟動:
可以通過這個命令面板快速的執(zhí)行命令襟铭。比如我這里將一個cell移動到它下一個cell的下面:在一個cell中(在command模式下)碌奉,然后按下 Ctrl + Shift + P ,輸入 move 寒砖,鍵盤方向鍵選擇要執(zhí)行的命令即可赐劣,然后按下回車即可執(zhí)行。