在服务器上使用jupyter

转载自在服务器上配置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='*' # 就是设置所有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...       # 刚才复制的那个密文'  
3.  c.NotebookApp.open_browser = False       # 禁止自动打开浏览器  
4.  c.NotebookApp.port =8888                         #随便指定一个端口  

第四步:配置一下路由器的端口转发,

第五步:在服务器端启动 jupyter notebook

第六步:本地地址栏输入服务器ip:8888 就OK了

2.打开 Jupyter Notebook

打开 notebook 的方法非常简单,只需在终端输入

ipython notebook

3.退出

在ubuntu终端运行jupyter notebook后打开了jupyter的网页,在关闭jupyter的网页后如何在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
   [...]

参考pip安装使用详解

4.安装python2 kernal

sudo python2 -m pip install --user --ignore-installed python-dateutil ipykernel

jupyter kernel查看内核

jupyter kernelspec list

卸载内核

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

出现问题:

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

这是由于系统自带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使用

参考Jupyter Notebook使用笔记(一)

两种模式

Command mode 和 Edit mode。 在一个cell中,按下Enter,进入Edit模式,按下Esc,进入Command 模式

运行当前cell,并移动到下一个Cell

在一个cell中(在command模式下),  Shift + Enter  

创建Cell

在一个cell中(在command模式下)
1\. 按下 a ,即可在这个cell之前创建一个新的cell;
2\. 按下 b,即可在这个cell之后创建一个新的cell;

Cell中 Code 和 Markdown的切换

在一个cell中(在command模式下)
1\. 按下 y, 进入Code;
2\. 按下m, 进入Markdown;

显示Cell中的行数

在一个cell中(在command模式下),按下 l

删除Cell

在一个cell中(在command模式下), 按两次 d

保存Notebook

在一个cell中(在command模式下), 按下 s

启动命令面板

在一个cell中(在command模式下), 按下 Ctrl + Shift + P 
界面中的小键盘也可以启动:

可以通过这个命令面板快速的执行命令。比如我这里将一个cell移动到它下一个cell的下面:在一个cell中(在command模式下),然后按下 Ctrl + Shift + P ,输入 move ,键盘方向键选择要执行的命令即可,然后按下回车即可执行。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,898评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,401评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,058评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,539评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,382评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,319评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,706评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,370评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,664评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,715评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,476评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,326评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,730评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,003评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,275评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,683评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,877评论 2 335

推荐阅读更多精彩内容