unoconv / unoserver

MIT License
496 stars 69 forks source link

No module named 'uno' #34

Closed touchsky2018 closed 1 year ago

touchsky2018 commented 2 years ago

I had install python3 and libreoffice, when i run libreoffice, No error when run unoserver, but, There is a error as following when I run unoconvert. Can you give some help. @regebro

Traceback (most recent call last): File "/usr/lib/python3.7/site-packages/unoserver/converter.py", line 2, in import uno ModuleNotFoundError: No module named 'uno'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/bin/unoconvert", line 5, in from unoserver.converter import main File "/usr/lib/python3.7/site-packages/unoserver/converter.py", line 5, in "Could not find the 'uno' library. This package must be installed with a Python " ImportError: Could not find the 'uno' library. This package must be installed with a Python installation that has a 'uno' library. This typically means you should installit with the same Python executable as your Libreoffice installation uses.

 at ChildProcess.exithandler (child_process.js:303:12)
 at ChildProcess.emit (events.js:310:20)
 at maybeClose (internal/child_process.js:1021:16)
 at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {

killed: false, code: 1, signal: null,

ccsrvs commented 2 years ago

We added the following environment variables to our running docker container and had success after facing the same issue:

export URE_BOOTSTRAP=vnd.sun.star.pathname:/usr/lib/libreoffice/program/fundamentalrc
export PATH=/usr/lib/libreoffice/program:$PATH
export UNO_PATH=/usr/lib/libreoffice/program
export LD_LIBRARY_PATH=/usr/lib/libreoffice/program:/usr/lib/libreoffice/ure/lib
export PYTHONPATH=/usr/lib/libreoffice/program:$PYTHONPATH

for additional context, we are running it in Alpine too, so we added the ENV's to our docker file.

mmahalwy commented 1 year ago

same here - no luck :(

lnfel commented 1 year ago

Solution is to run unoconvert using the python used by libreoffice.

# Install libreoffice python finder
wget -O find_uno.py https://gist.githubusercontent.com/regebro/036da022dc7d5241a0ee97efdf1458eb/raw/find_uno.py
python3 find_uno.py

# Run the python script
python find_uno.py
or
python3 find_uno.py

# On mac it is located at /Applications/LibreOffice.app/Contents/Resources/python
# Use libreoffice python to run unoserver and unoconvert
/Applications/LibreOffice.app/Contents/Resources/python -m unoserver.server --executable /usr/local/bin/soffice

# Then we can safely run unoconvert the same way
# unoconvert requires the outfile to be explicit
/Applications/LibreOffice.app/Contents/Resources/python -m unoserver.converter --convert-to pdf "Input.docx" "Out.pdf"