5

I've been searching all day for a solution and can't seem to find anything that works, just a bunch of a leads that seem outdated or non-functional.

I'm basically trying to get to a hello-world state either in python so that I can start programmatically creating document pages from database data.

I tried installing both libreoffice and openoffice. I installed the file in the default location (i did windows 7 (C:\Program Files (x86)\LibreOffice 4) and installed ubuntu 14 and tried the default path (/usr/lib/libreoffice) too).

I had trouble with the bat script () in the sdk folder so I even tried reinstalling in the base dir with no spaces c:\libreoffice in windows.

I tried many manipulations trying to change the PYTHON PATH settings and installing different versions of python.

Does anyone have any advice on how I can get python setup to make openoffice documents? just getting past the 'import uno' statement without an import error? I'm sure it's something dumb but I'm at a complete loss.

Thanks in advance.

EDIT: The error I got was the standard module not found error I got the error regardless of if I opened the python instance in my local version or the one residing in the libreoffice folder:

C:\Libreoffice\program\python-core-3.3.3\bin>python
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import uno
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'uno'

EDIT 2: I got past the 'uno' issue when I did a find and found uno.py in the program folder. I added that to my python path and uno loaded. However, now I get a different error:

Traceback (most recent call last):
  File "C:\Users\Alex\workspace\OOTest\test\test.py", line 7, in <module>
    import uno
  File "C:\Libreoffice\program\uno.py", line 21, in <module>
    import pyuno
ImportError: DLL load failed: The specified module could not be found.

I did a find and found the following:

C:\Libreoffice>find|grep pyuno*
./program/pyuno.pyd
./program/services/pyuno.rdb
./share/registry/pyuno.xcd

I tried to add the program folder to my windows path (already in the python path) and still have the same error.

Any advice on loading pyuno?

ThinkBonobo
  • 15,487
  • 9
  • 65
  • 80
  • 1
    Could you post the import error? Also with the command you used to install it? – Bioto Jul 25 '14 at 22:32
  • Did you search solution on StackOverflow ? For example: see `Related` on right side of this page. – furas Jul 25 '14 at 22:37
  • Thanks for taking a shot at this. @NicholasYoung - I updated my post to tell the error. – ThinkBonobo Jul 27 '14 at 15:07
  • @furas - I looked through the related and could not get a solution to work. Maybe I missed the one you're looking at, could you link me to it and I'll try it out. – ThinkBonobo Jul 27 '14 at 15:08
  • Are you using pip to install your modules? – Bioto Jul 27 '14 at 19:36
  • @NicholasYoung Do you know the name of the module? I've tried looking for the mod and I don't think you can use pip to install uno. http://www.openoffice.org/udk/python/python-bridge.html#install give instructions on installing and says it comes with openoffice/libreoffice, but I can't find it. – ThinkBonobo Jul 28 '14 at 13:55
  • https://wiki.openoffice.org/wiki/Using_Python_on_Windows – Bioto Jul 28 '14 at 15:11
  • If you're on Ubuntu, you might get lucky when you install the [python3-uno](http://packages.ubuntu.com/trusty/python3-uno) package. – Jens Oct 09 '14 at 14:59
  • Use the python that comes normally with libreoffice instead of your system python if that is a possibility. The LibreOffice internal python is patched to work out of the box with python. I think some of the packagers do something similar for the normal python through the python-uno package but would need to check that. – moggi Dec 18 '14 at 00:26

2 Answers2

1

For running uno from a different python I found that I had to set three values. On Win7 you may set all three as user defined environment values for the user account. Log off and on again for them to get working.

After some try&error I came up with the following solution.

In your lib\site-packages folder of your pythoninstallation add a OpenOffice.pth file with the path to your installations subfolder program like:

content of OpenOffice.path:
C:\Program Files (x86)\OpenOffice.org 4\basis\program

I did not get it working on Win7 with Python 2.7 to set this value from within the script. Thats why I use the .pth file. With OpenOffice 3.x the path wants to be to C:\Program Files (x86)\OpenOffice.org 3\basis\program.

import os
os.environ["URE_BOOTSTRAP"] = r"vnd.sun.star.pathname:C:\Program Files (x86)\OpenOffice 4\program\fundamental.ini"
os.environ["PATH"] += r";C:\Program Files (x86)\OpenOffice 4\program"
import uno

Within your script set two environ values to the fundamental.ini and to the subfolder \program.

With OpenOffice 3.x the second environ has got to look like this

os.environ["PATH"] += r";C:\Program Files (x86)\OpenOffice.org 3\URE\bin"

Of course you will have to change those paths to fit your installation. You may want to drop the BOOTSTRAP right after you imported uno, because that causes conflicts if you are running differen versions of OpenOffice or LibreOffice on the same machine.

os.environ.pop("URE_BOOTSTRAP")

Important! This will only work if your python is the same version as the python that comes with you OpenOffice, i.e. OpenOffice 3.x python 2.6 OpenOffice 4.x python 2.7 LibreOffice 4.x python 3.3

Danfro
  • 196
  • 4
  • I've moved on to a different approach to my issue, but I appreciate your detailed answer in case someone else runs into this (or I take a stab at this again). – ThinkBonobo Mar 11 '15 at 21:28
0

I have another solution for windows. On Windows you can create a symbolic link to a directory.

At the command prompt type:

mklink /J "C:\Users\YourUserXXXX\AppData\Local\Programs\Python\Python310\Lib\Uno\" "C:\Program Files (x86)\OpenOffice 4\program\"

this will create a symbolic link to the openoffice directory

C:\Users\YourUserXXXX\AppData\Local\Programs\Python\Python310\Lib\ and the library will be found in the environment.

Del
  • 667
  • 7
  • 23