Sta*_*ean 13 python file-upload jupyter-notebook jupyter-lab
我想FileUpload在 jupyter 实验室中使用小部件。我的笔记本单元中有以下几行代码:
uploader = widgets.FileUpload()
uploader
Run Code Online (Sandbox Code Playgroud)
在 jupyter notebook 中,单元格的输出是一个可点击的按钮,我可以用它来上传文件。在 jupyter 实验室中,输出如下:
FileUpload(value={}, description='Upload')
Run Code Online (Sandbox Code Playgroud)
这是有关uploader对象的信息:
Type: FileUpload
String form: FileUpload(value={}, description='Upload')
File: ~/miniconda3/envs/fastai2/lib/python3.7/site-packages/ipywidgets/widgets/widget_upload.py
Run Code Online (Sandbox Code Playgroud)
是否可以让这个小部件在 jupyter 实验室上工作?如果是这样,我应该如何进行?
Pav*_*kyi 12
如果你开箱即用地使用 jupyterlab,它默认没有启用 ipywidgets,你需要在启用扩展后重建它。按照此处的步骤操作:
pip install ipywidgetsjupyter nbextension enable --py widgetsnbextensionjupyter labextension install @jupyter-widgets/jupyterlab-manager它说较新的 Jupyterlab 已启用它,但我仍然遇到问题,具体取决于平台。手动安装通常是要走的路。
对我来说它之后起作用了
pip install jupyterlab-widgets
jupyter labextension install @jupyter-widgets/jupyterlab-manager
Run Code Online (Sandbox Code Playgroud)
另请参阅
https://developer.aliyun.com/mirror/npm/package/@jupyter-widgets/jupyterlab-manager
用法
from ipywidgets import FileUpload
from IPython.display import display
upload = FileUpload(accept='.txt', multiple=True)
display(upload)
Run Code Online (Sandbox Code Playgroud)
with open('z_merged_output.txt', 'wb') as output_file:
for uploaded_filename in upload.value:
content = upload.value[uploaded_filename]['content']
output_file.write(content)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5543 次 |
| 最近记录: |