jupyter:python可视化
安装
pip install jupyter
jupyter notebook --generate-config
使用密码登录
如果放在服务器上运行,需要使用密码登录,首先生成密码
from notebook.auth import passwd
passwd()
保存在配置文件jupyter_notebook_config.py
import os
c = get_config()
c.NotebookApp.password = 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
生成ssl证书
因为Jupyter必须要用https进行登录,所以需要生成ssl证书。
openssl req -x509 -nodes -days 3650 -newkey rsa:1024 -keyout ~/.jupyter/mykey.key -out ~/.jupyter/mycert.pem
更改Jupyter的配置文件中的相关字段。
c.NotebookApp.certfile = os.path.expanduser('~/.jupyter/mycert.pem')
c.NotebookApp.keyfile = os.path.expanduser('~/.jupyter/mykey.key')
其他设置
c.NotebookApp.ip = '*'
c.NotebookApp.port = 8888
c.NotebookApp.open_browser = False
安装Jupyter插件管理器
pip install jupyter_contrib_nbextensions jupyterlab
jupyterlab的目的是增强jupyter的编辑能力,使jupyter如IDE一般强大。
运行:jupyter-lab
在腾讯云主机上运行jupyter会报如下错误:
OSError: [Errno 99] Cannot assign requested address
启动时指定ip为0.0.0.0即可:
jupyter-lab --ip=0.0.0.0
显示matplotlib图片
第一种,在代码前面加一句:
%matplotlib inline
第二种,使用
ipython profile create
生成配置,修改ipython_config.py配置文件c.InteractiveShellApp.matplotlib = 'inline'