jupyter notebook切换环境_服务器搭建Jupyter Notebook环境

本文安装环境:Ubuntu 18.04.1, Python 3.7.6

Jupyter Notebook是什么?

Jupyter Notebook是一种可交互式笔记本[1],是数据分析中常用的工具。有两种开发模式,分别是JupyterLab, JupyterTree。

服务器搭建Jupyter Notebook环境

话不多说,下面开始动手操作,如已经安装Jupyter或者Anaconda[2],可以跳过步骤1。

  • 安装Jupyter
# 使用pip安装$ pip3 install jupyter
  • 生成Jupyter配置文件
$ jupyter notebook --generate-config# 返回Writing default config to: /home/ubuntu/.jupyter/jupyter_notebook_config.py
  • 生成Jupyter的密码
$ python3Python 3.7.6 (default, Jan  8 2020, 19:59:22)[GCC 7.3.0] :: Anaconda, Inc. on linuxType "help", "copyright", "credits" or "license" for more information.>>> from IPython.lib import passwd>>> passwd()Enter password: Verify password: 'sha1:......'>>> exit(); # 退出python
  • 设置Jupyter的配置文件
$ vim ~/.jupyter/jupyter_notebook_config.py# 将下面命令放在文件最后c.NotebookApp.ip = '*' #所有IP均能访问,也可以限制访问的IPc.NotebookApp.port = 8888 #访问端口设置c.NotebookApp.open_browser = False #不在服务器上打开浏览器c.NotebookApp.notebook_dir = '/home/ubuntu/XXX/jupyter' #设置Jupyter目录
  • 启动Jupyter

本步骤未开启后台运行,在服务器登出之后,服务也会中断;在后面的步骤会介绍,如何在服务器登出之后,服务依然运行。

$ jupyter notebook

或者

$ jupyterlab
  • 本地浏览器打开

输入网址:服务器IP地址:8888/token=,如打开说明已经成功。

3e09e079a896c67395b44c1c74b975e2.png

本地浏览器打开Jupyter

附录

后台运行Jupyter

# 后台运行Jupyter + 关闭方法# 1 后台运行Jupyter$ nohup jupyter notebook --no-browser > /home/ubuntu/XXX/logfile/error.log  2 关闭后台运行程序# 2.1 找到Jupyter的pid$ ps -ef | grep jupyter> ubuntu   22353     1  0 Jun24 ?        00:01:54 /usr/bin/python3 /home/ubuntu/.local/bin/jupyter-notebook --no-browser# 2.2 kill process$ kill -9 22353

计划

配置好Jupyter,就可以愉快地进行数据分析、数据挖掘了。下一篇文章总结一下Pandas这个分析常用包的使用。

jupyter notebook切换环境_服务器搭建Jupyter Notebook环境_第1张图片

爬树的panda

Reference

  1. notebook: https://jupyter-notebook.readthedocs.io/en/stable/notebook.html
  2. Anaconda: https://repo.anaconda.com/archive/

你可能感兴趣的:(jupyter,notebook切换环境)