利用Jupyter搭建在线Python编辑器

1. 创建虚拟环境

1
2
3
4
5
6
7
8
9
$ pip install virtualenv
$ ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv

$ mkdir jupyter #创建jupyter文件夹
$ cd jupyter
$ virtualenv venv #创建venv文件夹
New python executable in venv/bin/python
Installing distribute............done.
$ source venv/bin/activate #激活虚拟环境

2.安装Jupyter

1
$ pip install jupyter 

3.配置 Jupyter Notebook

生成配置文件,文件在 /root/.jupyter/jupyter_notebook_config.py

1
$ jupyter notebook --generate-config

设置密码

1
2
3
4
5
In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: '这里是密码'

修改配置,在生成的config.py文件最后加入

1
2
3
4
5
6
c.NotebookApp.ip = '*' #所有绑定服务器的IP都能访问,若想只在特定ip访问,输入ip地址即可
c.NotebookApp.port = 9000 #将端口设置为自己喜欢的吧,默认是9000
c.NotebookApp.open_browser = False #我们并不想在服务器上直接打开Jupyter Notebook,所以设置成False
c.NotebookApp.notebook_dir = '/root/jupyter_projects' #jupyter文件保存目录
c.NotebookApp.allow_root = True # 为了安全,Jupyter默认不允许以root权限启动jupyter
c.NotebookApp.password = u'上面生成的密码:sha1:***'

4.启动服务

1
$ jupyter notebook

在自己windows下用pip安装了,但在cmd里面一直提示jupyter不是命令,只能用python -m jupyter notebook来运行了或者用jupyter-notebook也可以。

5.设置主题

安装

1
pip install jupyterthemes

一种比较好看的配置

1
jt -t onedork -f fira -fs 10 -cellw 90% -ofs 8 -dfs 8 -T -T -N