Page 1 of 1

How to import uno with Python/macOS?

PostPosted: Thu Jan 11, 2018 1:14 am
by pasza
Any idea how to "import uno" within a Python script being managed by a system Python distribution?

> /usr/local/bin/python3
Python 3.6.4 (default, Jan 6 2018, 11:51:15)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
>>> import uno
ModuleNotFoundError: No module named 'uno'

Re: How to import uno with Python/macOS?

PostPosted: Thu Jan 11, 2018 1:37 am
by Villeroy
Use the Python interpreter that is shipped with the Office suite. It is Python3 with LibreOffice and Python2 with OpenOffice.
http://christopher5106.github.io/office ... acros.html
https://conference.libreoffice.org/asse ... sPyUNO.pdf

Re: How to import uno with Python/macOS?

PostPosted: Thu Jan 11, 2018 2:25 am
by pasza
Thanks. But there is no python at my AOO installation - how to get it?

> ll -1 /Applications/OpenOffice.app/Contents/MacOS/*python*
/Applications/OpenOffice.app/Contents/MacOS/pythonloader.py
/Applications/OpenOffice.app/Contents/MacOS/pythonloader.uno.dylib
/Applications/OpenOffice.app/Contents/MacOS/pythonloader.unorc
/Applications/OpenOffice.app/Contents/MacOS/pythonscript.py


P.S. I'd still like to use a python interpreter chosen by me.

Re: How to import uno with Python/macOS?

PostPosted: Thu Jan 11, 2018 12:48 pm
by Lupp
What about
Code: Select all   Expand viewCollapse view
(PieceOfPathToThe_soffice.exe)\program\python-core-2.7.6

Re: How to import uno with Python/macOS?

PostPosted: Thu Jan 11, 2018 2:46 pm
by RoryOF
On my Xubuntu system, uno.py is at /opt/openoffice4/program; Normally, when a python script is opened as a macro in OpenOffice this is found automatically. If you wish to use it in the python interpreter (say for debugging), you should add that to your PYTHONPATH.

To find python on your computer, try "whereis python" and "which python" in a terminal (no quotes)

Re: How to import uno with Python/macOS?

PostPosted: Thu Jan 11, 2018 5:13 pm
by MrProgrammer
Hi, and welcome to the forum.

pasza wrote:But there is no python at my AOO installation - how to get it?
With no Python configuration on Mac OSX 9.5 and OpenOffice 3.2 I have
~ $ find /Applications/OpenOffice.org.app/ -name uno.py
/Applications/OpenOffice.org.app//Contents/basis-link/program/uno.py
~ $ whereis python
/usr/bin/python
~ $ python -V
Python 2.7.5

As a test, try Tools → Macros → Run macro → OpenOffice macros → pythonSamples → TableSample → createTable → Run

~ $ find /Applications/OpenOffice.org.app/ -name TableSample.py
/Applications/OpenOffice.org.app//Contents/basis-link/share/Scripts/python/pythonSamples/TableSample.py

pasza wrote:I'd still like to use a python interpreter chosen by me.
That would seem to me to be a Python installation issue, not an OpenOffice issue.

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.

Re: How to import uno with Python/macOS?

PostPosted: Thu Jan 11, 2018 6:41 pm
by Villeroy
http://christopher5106.github.io/office ... acros.html explains LO-Python on the Mac and mentions the executable /Applications/LibreOffice.app/Contents/MacOS/python