本文记录 Jupyter Notebook 的简明使用指南.
文章目录
1. 安装 Jupyter Notebook
python 3(推荐)
python3 -m pip install --upgrade pip
python3 -m pip install jupyter
python 2
python -m pip install --upgrade pip
python -m pip install jupyter
virtual environment
pip install --upgrade pip
pip install jupyter
2. 运行 Jupyter Notebook
2.1 基本运行命令
点击这里,查看官方指南。
2.2 在服务器上运行
设定为服务器的IP地址,并指定端口号
jupyter notebook --ip xxx.xxx.xxx.xxx --port xxxx
例如,服务器使用的IP为 172.16.2.233,指定端口号为 8888
jupyter notebook --ip 172.16.2.233 --port 8888
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://172.16.2.233:8888/?token=277edfd3b1dd827a4641b0901f4b6eecedb0e861729a620d
3. 使用配置文件
3.1生成配置文件
jupyter notebook --generate-config
配置文件路径为:
~/.jupyter/jupyter_notebook_config.py
3.2 生成密钥
打开 python prompt.
from notebook.auth import passwd
passwd()
Enter password:
Verify password:
'sha1:feb73cb5561d:ebb2959943c9392da717ee22934da7514f3a441d'
************
3.3 修改配置文件
vim ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip='192.168.2.233' # 设置‘*’所有ip皆可访问,或者服务器IP地址
c.NotebookApp.password = u'sha1:feb73cb5561d:ebb2959943c9392da717ee22934da7514f3a441d' # 刚才复制的那个密文'
c.NotebookApp.open_browser = False # 禁止自动打开浏览器
c.NotebookApp.port = 8888 # 指定端口
3.4 按配置文件设置启动
jupyter notebook
4. 安装多内核 IPython kernel
为 Jupyter Notebook 添加 Python 虚拟环境解释器。
Installation Guide
- 激活虚拟环境
$ source venv2.7/bin/activate
- 安装
ipynernel
(venv2.7) $ pip install ipykernel
- 将虚拟环境 Python Interpreter 安装到 Jupyter Notebook
(venv2.7) $ python -m ipykernel install --user --name venv2.7 --display-name "Python2.7(venv2.7)"
Installed kernelspec venv2.7 in /home/homedirectory/.local/share/jupyter/kernels/venv2.7