Search code examples
pythonwindowsopenoffice.orgunopyuno

OpenOffice.org development with pyUno for Windows—which Python?


At home, on Linux, I've experimented with pyUNO to control OpenOffice.org using Python. I've been using Python 2.6. It all seems to work nicely.

Now I thought I would try one of my scripts (run a graphical diff for ODF doc) on Windows. But when I tried to run it, I got:

ImportError: No module named uno

According to udk: Python UNO Bridge and OpenOffice.org Running Python on Windows, I have to run the Python interpretter that's installed with OpenOffice.org.

Q1: Is Python 2.6 available for OpenOffice.org?

However, that interpreter is Python 2.3, which is getting a little old! and my script uses a feature not supported by 2.3 (subprocess module).

Q2: Can pyUNO programming on Windows be done with a pyUNO add-on to the standard Python distribution, not the Python that is bundled with OpenOffice.org?

In my searching so far, I haven't been able to find any indication that there is a pyUNO module available to be installed into the standard Python Windows distribution... which is a surprise because on Ubuntu Linux, UNO is supported just fine in Python just by:

 apt-get install python-uno

Another problem with this is: what if I want to make a program that uses both pyUNO and other 3rd party libraries? I can't install pyUNO into my Python installation on Windows, so am I forced to somehow install my other 3rd party libraries into OpenOffice.org's bundled Python? It makes it difficult to create larger, more full-featured programs.

Am I missing something, or are we stuck with this situation for now?


Solution

  • You can import uno into your system's python on Win32 systems. (Not Python 3 yet). Tutorial at http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=36370&p=166783 It's not difficult - import three environment variables, and append one item to your pythonpath.

    For additional flexibility, you can use the COM-UNO bridge instead of the Python-UNO bridge. The syntax is generally quite similar, and you can use any version of Python (including Python3). Info at http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=36608&p=167909