jupyter lab添加插件可以查看python file中函数定义等
文章目录
- 0. 更新jupyter lab
- OK
- 安装jupyterlab2.3.1版本
- 开启用户验证
- 折腾0
- 折腾1
- 折腾2
- 1. jupyterlab-go-to-definition
- 2. lsp插件
- 3. 报错:AttributeError: module 'typing' has no attribute '_SpecialForm'
- 4. Elyra插件
- 5. 目录插件
0. 更新jupyter lab
OK
安装jupyterlab2.3.1版本
参考:Failure to start jupyter lab — IndexError: pop from an empty deque
简单来说,就是jupyterlab 3.x版本还不是很稳定,有很多错误,直接降级到2.3.1
conda install jupyterlab=2.3.1
就降级就好了,然后默认打开的jupyterlab里就有jupyter toc插件,但是会提示需要你 build,在界面上点就行了
开启用户验证
但是这种安装好之后,默认没有token和密码设置(没有用户管理),去开一下。
感谢:Invalid Server Password in JupyterLab and Jupyter Notebook
如果是设置jupyter notebook的密码,可以
jupyter notebook password
如果是设置jupyter lab的密码,可以
jupyter server password
# 然后就会让你输入密码,再输入密码确认
查看jupyter lab相关路径,可以
$ jupyter lab path
Application directory: /opt/conda/share/jupyter/lab
User Settings directory: /root/.jupyter/lab/user-settings
Workspaces directory: /root/.jupyter/lab/workspaces
但是更好的方式其实是jupyter --path
:
$ jupyter --path
config:/root/.jupyter # 重点是这个文件夹/root/.local/etc/jupyter/opt/conda/etc/jupyter/usr/local/etc/jupyter/etc/jupyter
data:/root/.local/share/jupyter/opt/conda/share/jupyter/usr/local/share/jupyter/usr/share/jupyter
runtime:/root/.local/share/jupyter/runtime
在 /root/.jupyter
文件夹中,可以看到
root@XXX$ cd /root/.jupyter/
root@XXX:~/.jupyter$ ls
jupyter_notebook_config.json jupyter_server_config.json lab migrated nbconfig
主要就是这两个config文件
jupyter_notebook_config.json
- check if there is password setjupyter_server_config.json
- check if there is password set
参考:Why I can’t access remote Jupyter Notebook server?
如果启动jupyter lab的时候,显示让访问的端口不是默认的8888,可以在启动的时候添加参数:
jupyter notebook --ip xx.xx.xx.xx --port 8888
# 或者
jupyter lab --ip xx.xx.xx.xx --port 8888
折腾0
可能是因为之前设置过一些什么东西,去看一下jupyterlab的config,参考:Advanced Usage
# 先去看一下jupyter lab的配置文件在哪
root@XXXXXX:/home$ jupyter lab path
Application directory: /opt/conda/share/jupyter/lab
User Settings directory: /root/.jupyter/lab/user-settings
Workspaces directory: /root/.jupyter/lab/workspaces# 查看/root/.jupyter/lab/user-settings的内容(我显示没有这个文件夹。。),但是紧接着在参考文档里看到了
jupyter lab build
# 这个代码会rebuild jupyter的app目录,类似重构的感觉吧[LabBuildApp] WARNING | The extension "jupyterlab_tensorboard" is outdated.
[LabBuildApp] WARNING | The extension "jupyterlab-jupytext" is outdated.
[LabBuildApp] WARNING | The extension "@jupyterlab/toc" is outdated.
折腾1
报错:AttributeError: 'JupytextContentsManager' object has no attribute 'preferred_dir'
conda update jupyterlab# 如果提示没法安,出现以下内容
PackageNotInstalledError: Package is not installed in prefix.prefix: /opt/condapackage name: jupyterlab# 就先用
conda install jupyterlab
# 去启动jupyterlab,还是有问题# 更新所有和jupyter相关的包,先查看自己的jupyter都依赖哪些包
$ jupyter --version
Selected Jupyter core packages...
IPython : 8.9.0
ipykernel : 6.20.2
ipywidgets : 8.0.4
jupyter_client : 8.0.1
jupyter_core : 5.1.5
jupyter_server : 2.1.0
jupyterlab : 3.5.3
nbclient : 0.7.2
nbconvert : 7.2.9
nbformat : 5.7.3
notebook : 6.5.2
qtconsole : 5.4.0
traitlets : 5.8.1# 全都更新
pip install --upgrade IPython ipykernel ipywidgets jupyter_client jupyter_core jupyter_server jupyterlab nbclient nbconvert nbformat notebook qtconsole traitlets # 还是不行,继续提示插件extension有问题,那就去更新和插件有关的包
pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install # 还是不行,但是我发现,直接使用jupyter notebook是没问题的,而且启动jupyter notebook服务之后,只需要把
127.0.0.1:8888/tree 换成127.0.0.1:8888/lab
# 也可以访问到jupyter lab的页面,但是没法执行代码# 最后的选择,全部更新,也不知道是什么地方出现了问题,那就全部更新好了。
conda update --all
参考:
- How to update jupyterlab using conda or pip
折腾2
建议使用
conda update jupyterlab
- 如果是使用conda安装的jupyterlab,则不建议使用
pip install --upgrade jupyterlab
,除非你要暂停conda环境(暂停jupyterlab服务),即:如果使用pip安装,就不是在线更新了,需要重启jupyter
参考:
- stackoverflow:How to update jupyterlab using conda or pip
但是在我实际使用的时候,出现了
$ conda update jupyterlabPackageNotInstalledError: Package is not installed in prefix.prefix: /opt/condapackage name: jupyterlab
所以还是使用pip进行了更新(更新了一大坨东西),最后提示需要rebuild jupyter lab,然后崩了。。
最后使用的方式是:
- 不是在jupyterlab的命令行里进行
conda update jupyterlab
- 去容器/服务器本地进行的
conda update jupyterlab
- 然后更新完重启
jupyter lab
就好了
但是重启之后还是安装不上,根据提示:
去查看extension
的版本,显示没有安装。。。继续去安装(参考:Jupyter Notebook Extensions)
pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install
依然提示以上错误,同时发现已有的插件其实也有不兼容的问题
参考:jupyter lab- Extensions官方文档
需要先安装nodejs
conda install -c conda-forge nodejs
然后就可以使用jupyter labextension
命令通过npm
来进行扩展包的安装和卸载管理了,例如
jupyter labextension install my-extension my-other-extension
# 或者是安装特定的版本
jupyter labextension install my-extension@1.2.3
使用以下命令:
# 针对这些包
JupyterLab Extension Package
>=1.2.1 <1.3.0 >=3.6.1 <4.0.0 @jupyterlab/application
>=1.2.1 <1.3.0 >=3.6.1 <4.0.0 @jupyterlab/docmanager
>=1.2.1 <1.3.0 >=3.6.1 <4.0.0 @jupyterlab/fileeditor
>=1.2.2 <1.3.0 >=3.6.1 <4.0.0 @jupyterlab/notebook
>=1.2.1 <1.3.0 >=3.6.1 <4.0.0 @jupyterlab/rendermime# 使用以下命令进行安装
#jupyter labextension uninstall @jupyterlab/toc
jupyter labextension install @jupyterlab/application@3.6.1
jupyter labextension install @jupyterlab/docmanager@3.6.1
jupyter labextension install @jupyterlab/fileeditor@3.6.1
jupyter labextension install @jupyterlab/notebook@3.6.1
jupyter labextension install @jupyterlab/rendermime@3.6.1
最后还是不好使,算了,不安这个插件了。。
由于希望使用jupyter lab
做开发,为了方便的查看函数定义,跳转到被引用的地方,因此搜索相应的插件
1. jupyterlab-go-to-definition
第一个搜到了jupyterlab-go-to-definition
,网上关于这个插件的教程也有很多。但是很不幸
- 在这个插件的Github主页:krassowski/jupyterlab-go-to-definition
- 提示这个项目已经不再维护了,作者把更多的精力用于维护lsp插件了,也就是下面的这个插件。
2. lsp插件
但是其有个要求Python3.7+,
- 这点必须满足,否则就会出现2. 报错:AttributeError: module ‘typing’ has no attribute ‘_SpecialForm’
安装其实很简单
pip install 'jupyterlab>=3.0.0,<4.0.0a0' jupyterlab-lsp
pip install 'python-lsp-server[all]'
然后重启就行,
- 详细的步骤去看官网Github主页的说明:jupyter-lsp/jupyterlab-lsp
如果不幸出错了,可能要求修改一下jupyter lab的插件配置,
- 那就参考 解决 jupyter-lab 安装插件后无法使用的问题(重新安装插件无法使用)
3. 报错:AttributeError: module ‘typing’ has no attribute ‘_SpecialForm’
File "/opt/conda/lib/python3.6/site-packages/typing_extensions.py", line 159, in <module>class _FinalForm(typing._SpecialForm, _root=True):
AttributeError: module 'typing' has no attribute '_SpecialForm'
根据参考内容,大概能知道应该是python版本过低。
- 在typing这个模块的github项目中,目前最新的是3.10版本,详见这里。在其中搜索
_SpecialForm
,可以看到:
- 切换到python3.6,即这里,再去搜索
_SpecialForm
,没有结果。说明python3.6的时候,typing模块是没有_SpecialForm这个属性的 - 切换下去,发现
python3.7
的时候就有了。 - 因此,只需要将python版本升级到3.7及以上就可以了
参考:
- huggingface论坛:AttributeError: module ‘typing’ has no attribute ‘_SpecialForm’
- python 3.6 - AttributeError: module ‘typing’ has no attribute ‘_SpecialForm’ #2
- AttributeError: module ‘typing’ has no attribute ‘_SpecialForm’
4. Elyra插件
参考:Elyra Documentation
这个插件是一个非常强大的插件,支持很多东西。
可以参考
- (数据科学学习手札95)elyra——jupyter lab平台最强插件集
- 在Jupyter Lab中搭建Python工作流
5. 目录插件
直接在jupyterlab的插件tab里找 toc-extension
,点击那个Install
(样式不像是按钮,但是确实是安装命令)
如果不幸提示:
就参考0. 更新jupyter lab,更新一下自己的jupyterlab版本吧
jupyter lab添加插件可以查看python file中函数定义等相关推荐
- sv验证中记分板的作用_将记分员添加到您的Python游戏中
sv验证中记分板的作用 这是有关使用Pygame模块在Python 3中创建视频游戏的系列文章的第10部分. 以前的文章是: 通过构建一个简单的骰子游戏,学习如何用Python编程 使用Pygame模 ...
- Python使用property函数定义属性访问方法如果不定义fget会怎么样?
我们知道Python使用property函数定义属性访问方法时的语法如下: 实例属性=property(fget=None, fset=None, fdel=None, doc=None) 而是要@p ...
- 查看python包中所有方法_获取Python包中的所有类名
我需要获取 Python包中所有类的列表. 起初我得到所有文件名(它工作正常,从stackoverflow获取): from os import listdir, getcwd from os.pat ...
- python中函数定义_Python中函数的定义与使用
原博文 2020-02-27 16:46 − 一.函数基本定义 定义函数的目的是为了让一段代码可以被重复使用 函数定义的语法: def 函数名([参数,参数.....]): 函数主体代码(多行代码) ...
- python设计一个函数定义计算并返回n价调和函数_音乐编程语言musicpy教程(第三期) musicpy的基础语法(二)...
这个是我在github上给我的项目musicpy写的wiki,分为数据结构,基础语法,实际应用三大部分来为大家讲解这门音乐编程语言,主要是想给大家写一个musicpy的详细的教程与介绍,目前wiki只 ...
- python中什么是关键字参数_如何使用python语言中函数的关键字参数的用法
一般情况下,在调用函数时,使用的是位置参数,即是按照参数的位置来传值:关键字参数是按照定义函数传入的参数名称来传值的.那么,关键字参数怎么使用? 工具/原料 python pycharm 截图工具 W ...
- python语言中函数在调用前必须先定义吗_Python函数必须先定义,后调用说明(函数调用函数例外)...
java开发者在定义类中的方法时,不会关心方法的定义相对于调用语句的位置. 但是python中需要注意: 函数必须先定义.后调用(函数调用函数例外). 如下为示例说明: 1.python函数的应用一般 ...
- python中使用函数编程的意义_总结Python编程中函数的使用要点
为何使用函数 最大化代码的重用和最小化代码冗余 流程的分解 编写函数 >>def语句 在Python中创建一个函数是通过def关键字进行的,def语句将创建一个函数对象并将其赋值给一个变量 ...
- 编程软件python中的if用法-总结Python编程中函数的使用要点
为何使用函数 最大化代码的重用和最小化代码冗余 流程的分解 编写函数 >>def语句 在Python中创建一个函数是通过def关键字进行的,def语句将创建一个函数对象并将其赋值给一个变量 ...
最新文章
- 原生js清空上一个元素内容_原生JS实现动态添加新元素、删除元素方法
- RandomAccessFile r rw rws rwd之间的区别
- Windows10文件重命名/复制/移动时,导致文件资源管理器卡顿,解决方案
- Linux Shell脚本专栏_批量主机远程执行命令脚本_08
- maven的基础入门
- jave导出mysql_java导出mysql数据到excel(poi)
- 测试sql server服务是否配置正确
- php随机显示怎么,PHP 随机显示
- python编写程序掷骰子游戏_python学习之掷骰子游戏
- 老徐WEB:js入门学习 - javascript变量的数据类型
- 服务器要输入exit才会读系统,脚本经典小窍门
- 如何在OUTLOOK签名中自动加入日期
- 【目标跟踪】|单目标跟踪指标
- linux装windows报错,安装Windows 和 Linux双系统(vmware) Centos7
- 【二】头歌平台实验-离散数学逻辑与推理
- E融汇移动端灰度发布功能演进
- 生产答疑_生产周会和数字例会
- 阳光的测试工作历程(转载)
- 掌握这些操作技巧,设置USB调试模式不难
- 完整的ChatRoom聊天室代码