peteut / ipython-file-upload Goto Github PK
View Code? Open in Web Editor NEWIPython file upload widget. Now obsolete, refer to widgets.https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#File-Upload
IPython file upload widget. Now obsolete, refer to widgets.https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#File-Upload
In ipywidgets 7.0, attributes can be binary and will then be synced with binary messages. That may make a big difference for large files (instead of base64 encoding them).
Also, FYI, @draperjames was looking into making a standard file upload widget in the base ipywidgets package (jupyter-widgets/ipywidgets#1542). Would you be willing to collaborate on such a standard widget?
Thanks for writing this!
As suggested by @oschuett, nbextensions
shall be installed via setup.py
. Refer to widget-cookiecutter for a template.
I just tried to install ipython-file-upload and got the error NameError: global name 'PermissionError' is not defined
. I found that there
> was no PermissionError in Python 2.7, it was introduced in the Python 3.3.
I'd suggest to add Python 3 a requirement or adopt the code for python 2.7 compatibility.
Can't seem to figure out where this is uploading the file. Tried on remote server + localhost with no success. I get no errors or warnings, it prints 'uploaded' but I can't see the uploaded test file.
Installing from notebook - updates notebook, ipython, and ipywidgets. Is it bad idea to continue running this notebook, i.e. do I need to restart the notebook+server? Looks like installation fails at setuptools
.
!pip install -U fileupload
Collecting fileupload
Downloading fileupload-0.1.1-py2.py3-none-any.whl
Collecting ipywidgets>=4.0 (from fileupload)
Downloading ipywidgets-5.1.3-py2.py3-none-any.whl (43kB)
Collecting notebook>=4.0 (from fileupload)
Downloading notebook-4.2.0-py2.py3-none-any.whl (6.7MB)
Requirement already up-to-date: traitlets>=4.0 in c:\python\python27_32b\lib\site-packages (from fileupload)
Collecting ipython>=4.0.0 (from ipywidgets>=4.0->fileupload)
Downloading ipython-4.2.0-py2-none-any.whl (736kB)
Requirement already up-to-date: ipykernel>=4.2.2 in c:\python\python27_32b\lib\site-packages (from ipywidgets>=4.0->fileupload)
Collecting widgetsnbextension>=1.2.2 (from ipywidgets>=4.0->fileupload)
Downloading widgetsnbextension-1.2.2-py2.py3-none-any.whl (1.5MB)
Requirement already up-to-date: tornado>=4 in c:\python\python27_32b\lib\site-packages (from notebook>=4.0->fileupload)
Requirement already up-to-date: jupyter-client in c:\python\python27_32b\lib\site-packages (from notebook>=4.0->fileupload)
Requirement already up-to-date: nbformat in c:\python\python27_32b\lib\site-packages (from notebook>=4.0->fileupload)
Requirement already up-to-date: jupyter-core in c:\python\python27_32b\lib\site-packages (from notebook>=4.0->fileupload)
Collecting nbconvert (from notebook>=4.0->fileupload)
Downloading nbconvert-4.2.0-py2.py3-none-any.whl (319kB)
Requirement already up-to-date: ipython-genutils in c:\python\python27_32b\lib\site-packages (from notebook>=4.0->fileupload)
Requirement already up-to-date: jinja2 in c:\python\python27_32b\lib\site-packages (from notebook>=4.0->fileupload)
Collecting pickleshare (from ipython>=4.0.0->ipywidgets>=4.0->fileupload)
Downloading pickleshare-0.7.2-py2.py3-none-any.whl
Requirement already up-to-date: simplegeneric>0.8 in c:\python\python27_32b\lib\site-packages (from ipython>=4.0.0->ipywidgets>=4.0->fileupload)
Collecting backports.shutil-get-terminal-size (from ipython>=4.0.0->ipywidgets>=4.0->fileupload)
Downloading backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
Requirement already up-to-date: decorator in c:\python\python27_32b\lib\site-packages (from ipython>=4.0.0->ipywidgets>=4.0->fileupload)
Collecting setuptools>=18.5 (from ipython>=4.0.0->ipywidgets>=4.0->fileupload)
Downloading setuptools-21.0.0-py2.py3-none-any.whl (509kB)
Collecting pygments (from nbconvert->notebook>=4.0->fileupload)
Downloading Pygments-2.1.3-py2.py3-none-any.whl (755kB)
Requirement already up-to-date: mistune!=0.6 in c:\python\python27_32b\lib\site-packages (from nbconvert->notebook>=4.0->fileupload)
Collecting entrypoints (from nbconvert->notebook>=4.0->fileupload)
Downloading entrypoints-0.2.1-py2.py3-none-any.whl
Requirement already up-to-date: MarkupSafe in c:\python\python27_32b\lib\site-packages (from jinja2->notebook>=4.0->fileupload)
Collecting pathlib2 (from pickleshare->ipython>=4.0.0->ipywidgets>=4.0->fileupload)
Downloading pathlib2-2.1.0-py2.py3-none-any.whl
Collecting configparser (from entrypoints->nbconvert->notebook>=4.0->fileupload)
Downloading configparser-3.3.0r2.tar.gz
Requirement already up-to-date: six in c:\python\python27_32b\lib\site-packages (from pathlib2->pickleshare->ipython>=4.0.0->ipywidgets>=4.0->fileupload)
Building wheels for collected packages: configparser
Running setup.py bdist_wheel for configparser: started
Running setup.py bdist_wheel for configparser: finished with status 'done'
Stored in directory: C:\Users\denis.akhiyarov\AppData\Local\pip\Cache\wheels\ed\ba\4d\7ae619b8bedfb950c8e9a8155d21fa96317f3fd8f03270652c
Successfully built configparser
Installing collected packages: pathlib2, pickleshare, backports.shutil-get-terminal-size, setuptools, ipython, pygments, configparser, entrypoints, nbconvert, notebook, widgetsnbextension, ipywidgets, fileupload
Found existing installation: pickleshare 0.5
Uninstalling pickleshare-0.5:
Successfully uninstalled pickleshare-0.5
Found existing installation: setuptools 20.3
Cannot remove entries from nonexistent file c:\python\python27_32b\lib\site-packages\easy-install.pth
Without CI and some basic tests, it is hard to believe that something is working in this extension.
At least people can look at YAML and installation logs to see all dependencies, which are complicated due to distributed jupyter ecosystem.
I will try to run this on linux mint with chrome and mozilla browsers.
dta@dta-Inspiron-N5050 ~ $ jupyter nbextension install --py fileupload
Installing /home/dta/anaconda3/lib/python3.5/site-packages/fileupload/static -> fileupload
Traceback (most recent call last):
File "/home/dta/anaconda3/bin/jupyter-nbextension", line 11, in <module>
sys.exit(main())
File "/home/dta/anaconda3/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/home/dta/anaconda3/lib/python3.5/site-packages/traitlets/config/application.py", line 596, in launch_instance
app.start()
File "/home/dta/anaconda3/lib/python3.5/site-packages/notebook/nbextensions.py", line 952, in start
super(NBExtensionApp, self).start()
File "/home/dta/anaconda3/lib/python3.5/site-packages/jupyter_core/application.py", line 256, in start
self.subapp.start()
File "/home/dta/anaconda3/lib/python3.5/site-packages/notebook/nbextensions.py", line 730, in start
self.install_extensions()
File "/home/dta/anaconda3/lib/python3.5/site-packages/notebook/nbextensions.py", line 710, in install_extensions
logger=self.log)
File "/home/dta/anaconda3/lib/python3.5/site-packages/notebook/nbextensions.py", line 239, in install_nbextension_python
destination=dest, logger=logger
File "/home/dta/anaconda3/lib/python3.5/site-packages/notebook/nbextensions.py", line 140, in install_nbextension
ensure_dir_exists(nbext)
File "/home/dta/anaconda3/lib/python3.5/site-packages/ipython_genutils/path.py", line 167, in ensure_dir_exists
os.makedirs(path, mode=mode)
File "/home/dta/anaconda3/lib/python3.5/os.py", line 231, in makedirs
makedirs(head, mode, exist_ok)
File "/home/dta/anaconda3/lib/python3.5/os.py", line 241, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/share/jupyter'
https://github.com/peteut/ipython-file-upload/blob/master/fileupload/widget.py#L33
The implementation of super()
is not compatible with Python 2.x. The following is, however:
super(FileUploadWidget, self).__init__(*args, **kwargs)
Replacing the one with the other, everything works perfectly. Not sure if you want to extend support to both Python 2 and Python 3 (and have potentially twice as many bugs to find. : ).
In any case, thanks a million for this library, it's exactly what we needed!
still not working on Windows - tried latest PyPi and master.
note that this demo is working:
https://github.com/ipython/ipywidgets/blob/master/docs/source/examples/File%20Upload%20Widget.ipynb
Hi Alain,
I was wondering if you could make a new release and upgrade the PyPI package accordingly?
Cheers,
Ole
Hi and thanks for your code.
The widget hangs when I try to upload a big file (126 Mb) - even with a local notebook server. How can this be circumvented?
pip list:
alabaster (0.7.7)
anaconda-client (1.4.0)
anaconda-navigator (1.1.0)
argcomplete (1.0.0)
astropy (1.1.2)
Babel (2.2.0)
backports-abc (0.4)
backports.shutil-get-terminal-size (1.0.0)
backports.ssl-match-hostname (3.4.0.2)
beautifulsoup4 (4.4.1)
bitarray (0.8.1)
blaze (0.9.1)
bokeh (0.11.1)
boto (2.39.0)
Bottleneck (1.0.0)
cdecimal (2.3)
cffi (1.5.2)
chest (0.2.3)
cloudpickle (0.1.1)
clyent (1.2.1)
colorama (0.3.7)
comtypes (1.1.2)
conda (4.0.5)
conda-build (1.20.0)
conda-env (2.4.5)
conda-manager (0.3.1)
configobj (5.0.6)
configparser (3.3.0.post2)
cryptography (1.3)
cycler (0.10.0)
Cython (0.23.4)
cytoolz (0.7.5)
dask (0.8.1)
datashape (0.5.1)
decorator (4.0.9)
dill (0.2.4)
docopt (0.6.2)
docutils (0.12)
entrypoints (0.2.1)
enum34 (1.1.2)
et-xmlfile (1.0.1)
fastcache (1.0.2)
fileupload (0.1.1)
Flask (0.10.1)
Flask-Cors (2.1.2)
funcsigs (0.4)
futures (3.0.3)
gevent (1.1.0)
greenlet (0.4.9)
grin (1.2.1)
h5py (2.5.0)
haxor (0.3.1)
HeapDict (1.0.0)
idna (2.0)
ipaddress (1.0.14)
ipykernel (4.3.1)
ipython (4.2.0)
ipython-genutils (0.1.0)
ipywidgets (5.1.3)
itsdangerous (0.24)
jdcal (1.2)
jedi (0.9.0)
Jinja2 (2.8)
jsonschema (2.4.0)
jupyter (1.0.0)
jupyter-client (4.2.2)
jupyter-console (4.1.1)
jupyter-core (4.1.0)
jupyter-kernel-gateway (0.5.1)
llvmlite (0.9.0)
locket (0.2.0)
lxml (3.6.0)
MarkupSafe (0.23)
matplotlib (1.5.1)
menuinst (1.3.2)
mistune (0.7.2)
mpmath (0.19)
multipledispatch (0.4.8)
nbconvert (4.2.0)
nbformat (4.0.1)
networkx (1.11)
nltk (3.2)
nose (1.3.7)
notebook (4.2.0)
numba (0.24.0)
numexpr (2.5)
numpy (1.10.4)
odo (0.4.2)
openpyxl (2.3.2)
pandas (0.18.0)
partd (0.3.2)
path.py (0.0.0)
pathlib2 (2.1.0)
patsy (0.4.0)
pep8 (1.7.0)
pickleshare (0.7.2)
Pillow (3.1.1)
pip (8.1.1)
ply (3.8)
prompt-toolkit (0.60)
psutil (3.4.2)
ptipython (1.0.0)
ptpython (0.32)
py (1.4.31)
pyasn1 (0.1.9)
pycosat (0.6.1)
pycparser (2.14)
pycrypto (2.6.1)
pyflakes (1.1.0)
Pygments (2.1.3)
PyInstaller (3.1.1)
pyodbc (3.0.10)
pyOpenSSL (0.15.1)
pyparsing (2.0.3)
pyreadline (2.1)
pytest (2.8.5)
Python-contrib-nbextensions (alpha)
python-dateutil (2.5.1)
pythonnet (2.1.0)
pytz (2016.2)
pywin32 (220)
PyYAML (3.11)
pyzmq (15.2.0)
QtAwesome (0.3.2)
qtconsole (4.2.0)
QtPy (1.0)
requests (2.10.0)
rope (0.9.4)
scandir (1.2)
scikit-image (0.12.3)
scikit-learn (0.17.1)
scipy (0.17.0)
seaborn (0.7.0)
setuptools (21.0.0)
simplegeneric (0.8.1)
singledispatch (3.4.0.3)
six (1.10.0)
snowballstemmer (1.2.1)
sockjs-tornado (1.0.1)
sphinx (1.3.5)
sphinx-rtd-theme (0.1.9)
spyder (2.3.8)
SQLAlchemy (1.0.12)
statsmodels (0.6.1)
sympy (1.0)
tables (3.2.2)
toolz (0.7.4)
tornado (4.3)
traitlets (4.2.1)
unicodecsv (0.14.1)
wcwidth (0.1.6)
Werkzeug (0.11.4)
wheel (0.29.0)
widgetsnbextension (1.2.2)
xlrd (0.9.4)
XlsxWriter (0.8.4)
xlwings (0.7.0)
xlwt (1.0.0)
!jupyter nbextension enable --py --sys-prefix widgetsnbextension
Enabling notebook extension jupyter-js-widgets/extension...
- Validating: ok
def _upload():
_upload_widget = fileupload.FileUploadWidget()
def _cb(change):
decoded = io.StringIO(change['owner'].data.decode('utf-8'))
filename = change['owner'].filename
print('Uploaded `{}` ({:.2f} kB)'.format(
filename, len(decoded.read()) / 2 **10))
_upload_widget.observe(_cb, names='data')
display(_upload_widget)
_upload()
Widget Javascript not detected. It may not be installed properly. Did you enable the widgetsnbextension? If not, then run "jupyter nbextension enable --py --sys-prefix widgetsnbextension"
pip install notebook==4.0
pip install ipywidgets==4.0
pip install traitlets==4.0
and getting this error by following the tutorial:
import io
from IPython.display import display
import fileupload
# Install Javascript
fileupload.nbinstall()
def _upload():
_upload_widget = fileupload.FileUploadWidget()
def _cb(change):
decoded = io.StringIO(change['owner'].data.decode('utf-8'))
filename = change['owner'].filename
print('Uploaded `{}` ({:.2f} kB)'.format(
filename, len(decoded.read()) / 2 **10))
_upload_widget.observe(_cb, names='data')
display(_upload_widget)
_upload()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-ce4e1a87f45a> in <module>()
1 import io
2 from IPython.display import display
----> 3 import fileupload
4
5 # Install Javascript
/home/dta/anaconda3/lib/python3.5/site-packages/fileupload/__init__.py in <module>()
----> 1 from .widget import FileUploadWidget # noqa
2
3
4 def nbinstall(overwrite=False, user=True):
5 '''
/home/dta/anaconda3/lib/python3.5/site-packages/fileupload/widget.py in <module>()
13
14
---> 15 class FileUploadWidget(ipywidgets.DOMWidget):
16 '''File Upload Widget.
17 This widget provides file upload using `FileReader`.
/home/dta/anaconda3/lib/python3.5/site-packages/fileupload/widget.py in FileUploadWidget()
19 _view_static = os.path.abspath(
20 os.path.join(os.path.dirname(__file__), 'static', _packet_name()))
---> 21 _view_name = traitlets.Unicode('FileUploadView').tag(sync=True)
22 _view_module = traitlets.Unicode(
23 os.path.join('nbextensions', _packet_name(), _module_name())
AttributeError: 'Unicode' object has no attribute 'tag'
Refer to install_nbextension.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.