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?
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
Per openoffice's docs, the Python version supported is WAY behind -- "Efforts on moving PyUNO to Python 2.5 continue", 2.6 not even on the map. So "stuck with this situation for now" is a fair assessment!-)
OpenOffice.org 3.1 comes with Python 2.6.1. (As I recall, it was a fairly last-minute merge that ticked some people off, but it's there and it works.) Now the docs are the only thing hopelessly out-of-date. :)
来源:https://stackoverflow.com/questions/994429/openoffice-org-development-with-pyuno-for-windows-which-python