Pycharm配置Jupyter Notebook实现在linux server上开发与调试

在上一篇文章Pycharm配置Jupyter Notebook实现本地开发与调试中,我们知道Pycharm专业版内部集成了Jupyter notebook,通过简单配置即可实现Pycharm开发调试本地Jupyter Notebook的目的。而在实际中,我们可能需要直接在Linux服务器上运行Jupyter ,从而本地开发环境与远程服务器过多报错等问题。

可是若遵循上一篇文章的方法,直接修改Python解释器为远程解释器时,Pycharm会提示如下:
Pycharm配置Jupyter Notebook实现在linux server上开发与调试_第1张图片
这样我们只能另辟蹊径,好在Pycharm为我们提供了另一种方法使用连接到任何一台正在运行的Jupyter服务器上。这样,必须先在Linux服务器端配置并启动Jupyter。

下面仅简单记录一下配置过程与可能遇到的** bug **,防止忘记!!

  1. 检查jupyter笔记本版本,如果您的版本> 5.0,请移步官方文档 ,那里会告诉你什么更改以及如何操作
jupyter --version
  1. 创建一个笔记本配置文件,此文件的默认位置是位于主目录中的Jupyter文件夹:/home/lollows/.jupyter/jupyter_notebook_config.py
jupyter notebook --generate-config
  1. Edit the notebook config file
vim /home/lollows/.jupyter/jupyter_notebook_config.py
  1. The minimum set of configuration options that you should uncomment and edit in jupyter_notebook_config.py is the following:注意下面我注释了password,因为如果Jupyter启用密码,则默认情况下不会启用令牌(token)身份验证,而Pycahrm需要使用token来连接运行的Jupyter server。
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
#c.NotebookApp.password = u'sha1:8edfae1b217b:df011545abf9d858fb76797957fd6c12bbffe6c0'
c.NotebookApp.open_browser = False
# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 8888
c.NotebookApp.allow_remote_access = True
  1. 开启Jupyter server,注意下面的screen命令是可选的,使用screen可以将jupyter放在Linux后台,方便你对服务器进行进一步的操作,具体可参见Screen命令
#新开一个窗口,并命名为jupyter 
screen -S jupyter
#若出现Cannot open your terminal '/dev/pts/1' - please check.,run:
#script /dev/null

#在新开的窗口中打开Jupyter notebook
jupyter notebook

#使用Ctrl + A + D的快捷键将这一窗口放入后台,回到开启screen窗口之前的状态
#查看目前都有哪些窗口在后台运行
screen -ls

#close the Detached(even Attached) screen 6779
#screen -X -S 6779 quit
  1. 在Pycharm端,填写服务器的ip与token,注意每回重启jupyter都会重置token,请自行修改

Pycharm配置Jupyter Notebook实现在linux server上开发与调试_第2张图片

后记: 如果按照jupyter官网配置了ssl加密证书,Pycharm连接时会出现证书问题,看到Jetbrain官网,目前还没有更好的解决方法。如果自己用的话,不配置ssl问题应该也不大。

你可能感兴趣的:(python)