How to import uno with Python/macOS?

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
pasza
Posts: 2
Joined: Thu Jan 11, 2018 1:06 am

How to import uno with Python/macOS?

Post 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'
OpenOffice 4.1.5 on macOS 10.12.6
User avatar
Villeroy
Volunteer
Posts: 31323
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to import uno with Python/macOS?

Post 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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
pasza
Posts: 2
Joined: Thu Jan 11, 2018 1:06 am

Re: How to import uno with Python/macOS?

Post 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.
OpenOffice 4.1.5 on macOS 10.12.6
User avatar
Lupp
Volunteer
Posts: 3619
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How to import uno with Python/macOS?

Post by Lupp »

What about

Code: Select all

(PieceOfPathToThe_soffice.exe)\program\python-core-2.7.6
On Windows 10: LibreOffice 24.8.3 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
RoryOF
Moderator
Posts: 34785
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to import uno with Python/macOS?

Post 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)
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
MrProgrammer
Moderator
Posts: 5097
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: How to import uno with Python/macOS?

Post 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.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
Villeroy
Volunteer
Posts: 31323
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to import uno with Python/macOS?

Post 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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply