实现在本地开端口利用jupyterlab远程操作服务器
作者:互联网
实现在本地开端口利用jupyterlab远程操作服务器
======>>>>总结:
- 进入base 环境
- ps -ef | grep jupyter-lab #获取进程号
- which jupyter-lab #查看当前的jupyterlab
- kill -9 进程号 #杀掉进程
- conda activate 环境名 #启动自己的环境
- nohup jupyter-lab --config=/home/data/jupyter/jupyter_notebook_config.py & #"&"可以挂起进程
- 终端输入jupyter-lab –-config=/home/data/jupyter 即可启动jupyter-lab 进行验证。成功即可ctrl+c y 终止程序
- 终端输入 nohup jupyter-lab –-config=/home/data/jupyter &
- cd jupyter 到自己路径文件夹的jupter目录下
- 将已有的config文件拷贝到自己文件夹下的jupter里
- 到自己的data文件夹下新建一个 jupyter文件夹
- 如果自己文件夹的路径下有jupyter_notebook_config.py,则删除
- 找到一个有config文件的路径(或者根据一的步骤生成一个新的)
- 登陆服务器
- conda activate 自己的环境
- 创建配置文件
具体操作:
jupyter notebook的配置
1.浏览器打开jupyter,新建一个python文件,第一行输入:
from notebook.auth import passwd
2.shift+enter执行命令并进入下一行。下一行输入:passwd() ,回车后提示输入密码,输入两次。
3.哈希密码sha1:158c74966eda:9533217697d0c62f0db43414ec4e06d4072c1cecc2e97d
4.再次打开配置文件jupyter_notebook_config.py,找到c.NotebookApp.password=第三步的哈希密码,重启jupyter notebook即可
使用
1.终端输入:jupyter-lab --generate-config 会生成一个配置文件,成功后会显示文件路径(/Users/kyousugi/.jupyter/jupyter_notebook_config.py)
2.打开路径下的jupyter_notebook_config.py配置文件,找到c.NotebookApp.notebook_dir=修改为自己的工作目录
还需要修改的配置如下
c.NotebookApp.allow_root = True
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = 'sha1:bf8121ab2205:18c7e60055ed79ec2a19fcdb9241b2770b75b976'
c.ContentsManager.root_dir = '/storage/st2/testcode/'
二、启动jupyterlab
(否则启动的jupterlab是base环境下的,会导致jupterlab的环境不是自己的虚拟环境)
Eg. /home/data/jupyter/jupyter_notebook_config.py
rm jupyter_notebook_config.py
mkdir jupyter
cp /home/data/jupyter/jupyter_notebook_config.py ./
通过vim修改jupyter_notebook_config.py文件
vim jupyter_notebook_config.py
键盘按 i 进入编辑模式
改为自己的文件夹路径,并设置端口号
eg:
c.NotebookApp.notebook_dir = '/home/data'
c.NotebookApp.port = 8889 #端口号
c.LabApp.user_settings_dir = '/home/data/jupyter/lab/user-settings'
c.LabApp.workspaces_dir = '/home/data/jupyter/lab/workspaces'
按esc退出编辑模式
键盘输入 :wq 保存退出
回车 即可
用 & 在后台挂起程序使其不自动退出
nohup jupyter-lab --config=/home/data/jupyter/jupyter_notebook_config.py & #"&"可以挂起进程
QA:如果jupyterlab虚拟环境不对?
1.查看jupyterlab的虚拟环境:
ipython中
import os
os.sys.path
如果不是在anaconda/envs/自己的环境 的python,则杀掉jupyterlab进程并在相应的虚拟环境中重启
2.操作
3. 检查
ipython中
import os
os.sys.path
# os.sys.path.insert(0,"/home/anaconda3/envs/my/lib/python3.6/site-packages/")
查看当前环境变量路径
若成功切换jupyterlab的后台虚拟环境,
则可以成功import 自己环境下的包 例如import tensorflow
①修改terminal的settings
eg:
{
// Terminal
// @jupyterlab/terminal-extension:plugin
// Terminal settings.
// *************************************
// Font family
// The font family used to render text.
"fontFamily": "'DejaVu Sans Mono', 'Noto Sans Mono', 'Everson Mono', FreeMono, Menlo, Terminal, monospace",
// Font size
// The font size used to render text.
"fontSize": 16,
// Line height
// The line height used to render text.
"lineHeight": 1,
// Paste with Ctrl+V
// Enable pasting with Ctrl+V. This can be disabled to use Ctrl+V in the vi editor, for instance. This setting has no effect on macOS, where Cmd+V is available
"pasteWithCtrlV": true,
// Screen Reader Mode
// Add accessibility elements for use with screen readers.
"screenReaderMode": false,
// Scrollback Buffer
// The amount of scrollback beyond initial viewport
"scrollback": 1000,
// Shut down on close
// Shut down the session when closing the terminal.
"shutdownOnClose": false,
// Theme
// The theme for the terminal.
"theme": "inherit"
}
②修改editor的settings
{
// Text Editor
// @jupyterlab/fileeditor-extension:plugin
// Text editor settings.
// ***************************************
// Editor Configuration
// The configuration for all text editors.
// If `fontFamily`, `fontSize` or `lineHeight` are `null`,
// values from current theme are used.
"editorConfig": {
"autoClosingBrackets": true,
"fontFamily": null,
"fontSize": 15,
"lineHeight": null,
"lineNumbers": true,
"lineWrap": "on",
"matchBrackets": true,
"readOnly": false,
"insertSpaces": true,
"tabSize": 4,
"wordWrapColumn": 80,
"rulers": [],
"codeFolding": false
}
}
修改字体符合自己使用习惯即可
参考:
https://blog.csdn.net/qq_37950540/article/details/88396746
sunflower_sara 发布了72 篇原创文章 · 获赞 40 · 访问量 15万+ 私信 关注标签:jupyterlab,jupyter,py,开端,notebook,home,服务器,config 来源: https://blog.csdn.net/sunflower_sara/article/details/103939729