AlJohri / docx2pdf

MIT License
506 stars 96 forks source link

Error: FloatProgress not found. Please update jupyter and ipywidgets #12

Closed supermanleeg closed 4 years ago

supermanleeg commented 4 years ago

Hi Al,

I saw your package and wanted to give a trial. But I met some issue that needs your help.

I used pip to install docx2pdf and finished the installation. However, the traceback says 'ImportError: cannot import name 'convert' from 'docx2pdf' (unknown location)'.

So I tried jupyther notebook in which import has no issue. But I faced the following traceback and didn't know what the problem is. I have the .py file in the same folder as my .docx files. Can you help?

from docx2pdf import convert convert("Speech for Carey celebration in SH copy.docx","Speech for Carey celebration in SH copy.pdf")


NameError Traceback (most recent call last) ~/opt/miniconda3/lib/python3.7/site-packages/tqdm/notebook.py in statusprinter(, total, desc, ncols) 95 if total: ---> 96 pbar = IProgress(min=0, max=total) 97 else: # No total? Show info style bar with no progress tqdm status

NameError: name 'IProgress' is not defined

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)

in ----> 1 convert("Speech for Carey celebration in SH copy.docx","Speech for Carey celebration in SH copy.pdf") ~/opt/miniconda3/lib/python3.7/site-packages/docx2pdf/__init__.py in convert(input_path, output_path, keep_active) 102 paths = resolve_paths(input_path, output_path) 103 if sys.platform == "darwin": --> 104 return macos(paths, keep_active) 105 elif sys.platform == "win32": 106 return windows(paths, keep_active) ~/opt/miniconda3/lib/python3.7/site-packages/docx2pdf/__init__.py in macos(paths, keep_active) 60 61 total = len(list(Path(paths["input"]).glob("*.docx"))) if paths["batch"] else 1 ---> 62 pbar = tqdm(total=total) 63 for line in run(cmd): 64 try: ~/opt/miniconda3/lib/python3.7/site-packages/tqdm/notebook.py in __init__(self, *args, **kwargs) 206 total = self.total * unit_scale if self.total else self.total 207 self.container = self.status_printer( --> 208 self.fp, total, self.desc, self.ncols) 209 self.sp = self.display 210 ~/opt/miniconda3/lib/python3.7/site-packages/tqdm/notebook.py in status_printer(_, total, desc, ncols) 102 # #187 #451 #558 103 raise ImportError( --> 104 "FloatProgress not found. Please update jupyter and ipywidgets." 105 " See https://ipywidgets.readthedocs.io/en/stable" 106 "/user_install.html") ImportError: FloatProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
AlJohri commented 4 years ago

@supermanleeg docx2pdf uses tqdm for showing progress using from tqdm.auto import tqdm. This will try to use the jupyter version of the progress bar when running in a jupyter environment.

As you can see from the error message, ImportError: FloatProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html

I think if you run pip install ipywidgets it should fix your problem. Let me know if that works

supermanleeg commented 4 years ago

Hi Al, Thank you for your answer. Unfortunately, it gives me the exactly same traceback after running pip install ipwidgets. BTW, this is on a Mac. Not sure if this is relevant.

I even added the 2nd line. from docx2pdf import convert from ipywidgets import FloatProgress

AlJohri commented 4 years ago

@supermanleeg I think i missed a step after the pip install. Run: jupyter nbextension enable --py widgetsnbextension

I'll try and replicate this in a fresh environment when I get a chance.

in the mean time, are you using a virtual environment? Can you run pip freeze in the terminal (after activating the venv) and paste the results?

supermanleeg commented 4 years ago

Hi Al, thanks a lot for your reply. After running jupyter nbextension enable --py widgetsnbextension. The code finally works. When the code is running, .docx files are also being opened and closed one by one. Is there a way to let it run in the background?

I think I'm not using a visual environment.

Here's what I get after running pip freeze:

appnope==0.1.0 appscript==1.1.0 asn1crypto==1.3.0 attrs==19.3.0 backcall==0.1.0 bleach @ file:///home/conda/feedstock_root/build_artifacts/bleach_1588608214987/work certifi==2020.4.5.1 cffi==1.14.0 chardet==3.0.4 comtypes==1.1.7 conda==4.8.3 conda-package-handling==1.6.0 cryptography==2.8 cycler==0.10.0 decorator==4.4.2 defusedxml==0.6.0 docx2pdf==0.1.7 entrypoints==0.3 idna==2.8 importlib-metadata==1.6.0 ipykernel==5.2.1 ipython @ file:///Users/runner/miniforge3/conda-bld/ipython_1588362986989/work ipython-genutils==0.2.0 ipywidgets==7.5.1 jedi==0.17.0 Jinja2==2.11.2 jsonschema==3.2.0 jupyter-client==6.1.3 jupyter-core==4.6.3 kiwisolver==1.2.0 MarkupSafe==1.1.1 matplotlib==3.2.1 mistune==0.8.4 nbconvert==5.6.1 nbformat==5.0.6 notebook @ file:///Users/runner/miniforge3/conda-bld/notebook_1588887229329/work numpy==1.18.4 packaging==20.1 pandas==1.0.3 pandocfilters==1.4.2 parso==0.7.0 pexpect==4.8.0 pickleshare==0.7.5 prometheus-client==0.7.1 prompt-toolkit==3.0.5 ptyprocess==0.6.0 pycosat==0.6.3 pycparser==2.19 Pygments==2.6.1 pyOpenSSL==19.1.0 pyparsing==2.4.7 pyrsistent==0.16.0 PySocks==1.7.1 python-dateutil==2.8.1 pytz==2020.1 pyzmq==18.1.1 requests==2.22.0 ruamel-yaml==0.15.87 Send2Trash==1.5.0 six==1.14.0 terminado==0.8.3 testpath==0.4.4 tornado==6.0.4 tqdm==4.42.1 traitlets==4.3.3 urllib3==1.25.8 wcwidth==0.1.9 webencodings==0.5.1 widgetsnbextension==3.5.1 workbook==1.1 xlrd==1.2.0 xlutils==2.0.0 xlwt==1.3.0 zipp==3.1.0

AlJohri commented 4 years ago

When the code is running, .docx files are also being opened and closed one by one. Is there a way to let it run in the background?

It's a bit hard. I made some attempts to try to make that happen here: https://github.com/AlJohri/docx2pdf/blob/master/docx2pdf/convert.jxa#L109-L116

If I remember correctly, I think if you completely close Word and let the script start Word independently, it will do it in the "background". It will still open each file individually but I think you can continue to do other things in the foreground (as long as those things don't involve MS Word).

Masumi-M commented 3 years ago

This error occurred for my program too, but I solved the problem by changing the name of python script to main.py from docx2pdf.py.

AlJohri commented 3 years ago

nice debugging @Masumi-M!