局域网连接服务器端jupyter实现python的远程代码调试(非root用户)
一、安装Anaconde
由于要使用python3所以需要安装Anaconde3,这里我们使用清华镜像
进行安装;
$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Linux-x86_64.sh # 64位系统
安装Anaconde3
$ bash Anaconda3-4.2.0-Linux-x86_64.sh
安装完成后环境变量会自动写到配置文件中,但此时还未生效,需要执行(此命令需要在用户目录下执行):
$ source ./.bashrc
如果显示不存在文件,或者文件中不存在程序路径,将环境变量添加到.bashrc再进行source即可。
当Anaconde3安装完成后,jupyter已经安装完成,此时我们需要对jupyter进行配置,使其能够实现远端登录。
二、配置jupyter
1、生成配置文件jupyter_notebook_config.py
$ jupyter notebook --generate-config
Ubuntu 下一般会保存在~/.jupyter/jupyter_notebook_config.py
2、设置登录密码
jupyter5.0后的版本,可以使用jupyter notebook password
来设置密码:
$ jupyter notebook password
Enter password: yourcode #输入密码
Verify password: yourcodeagain #再次输入密码确认
#运行后结果
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
密码被保存的位置~/.jupyter/jupyter_notebook_config.json
注:如显示[C 13:38:17.936 NotebookApp] No such file or directory: /home/xxx/password
表明jupyter notebook不是最新版本,将jupyter notebook进行更新即可:
$ conda update jupyter notebook
3、修改配置文件
我们需要对配置文件进行修改,方可完成jupyter的远程连接;
cd
到.jupyter文件夹,一般在用户目录下:
$ cd .jupyter
我使用vim完成jupyter_notebook_config.py
文件的配置:
$ vim jupyter_notebook_config.py
将文件中以下三行前的#去掉,并做相应修改:
c.NotebookApp.ip = '*' #允许所有ip访问 补充:报错 No address associated with hostname可设置为:'0.0.0.0'
c.NotebookApp.open_browser = False #不打开浏览器
c.NotebookApp.port = 9999 #端口为9999
tip:在vim中按键盘字母A
开始插入模式,按Esc
退出插入模式,按/
进行字符串匹配;
这时我们就可以在本地浏览器输入ip:9999进行连接了,连接成功后输入密码即可使用。
4、修改jupyter的默认路径
当我们完成上述配置后,发现jupyter的默认路径为我们的用户路径,这时我们设置jupyter的默认路径,让此路径专门为jupyter服务;
我们同样cd到.jupyter目录下,并使用vim对jupyter_notebook_config.py
文件进行编辑:
找到以下两行文字:
## The default URL to redirect to from `/`
#c.NotebookApp.default_url = '/tree'
去掉第二行的#并设置为如下(注意:设置的目录必须存在):
c.NotebookApp.default_url = '/tree'
以及这一行
c.NotebookApp.notebook_dir = '/your_work_path'
保存文件退出后重启jupyter即可得到干净清爽的界面!
https://blog.csdn.net/u014636245/article/details/83652126
https://blog.csdn.net/meizhuxun7340/article/details/86596523