I have read that OO supplies it's own python and uno.py [for 3.3 under ..\basis\program] - but there are ways to incorporate it into your current version such that a script can issue import uno w/out issue. I have tried scripts that supposedly permit this and tried to work through steps to perform it manually. Either my PC hangs or the results are NADA. Does anyone have a clear-cut procedure to make this work?:?:

OK. So here is code I tried. It simply locked my PC and I had to reboot.

import os
import sys
import subprocess

def import_uno():

    # Variables
    python_oo_executable = 'c:\\Program Files\\OpenOffice.org 3\\Basis\\program\\python.exe'    #2
    python_oo_script = '-cimport os ;print(os.environ["URE_BOOTSTRAP"]) ;print(os.environ["UNO_PATH"]) ;print(os.environ["PATH"])'                    #3, #4, #5
    path_to_uno = 'C:\\Program Files\\OpenOffice.org 3\\Basis\\program'        #6

    # Get the environment variables from OO-Python using subprocess
    process = subprocess.Popen([python_oo_executable, python_oo_script], stdout=subprocess.PIPE)
    result = process.communicate()
    environment_variables = result[0].split('\r\n')   # Three items in the list, one for each env var

    os.environ['URE_BOOTSTRAP'] = environment_variables[0]          #3
    os.environ['UNO_PATH'] = environment_variables[1]                   #4

    new_paths = environment_variables[2].split(';')
    existing_paths = os.environ['PATH'].split(';')
    for path in new_paths:
        if path not in existing_paths:
            existing_paths.append(path)
    os.environ['PATH'] = ';'.join(existing_paths)       #5

    sys.path.append(path_to_uno)                        #6

    return

# Begin Main
import_uno()
import uno
do_more_of_my_work()
do_the_rest_of_my_work()
# End Main

Do the command first from command line. I think you should have each line of code quoted or alternatively pass the name of script file. I also do not see much benefit from this compared to saving the paths to configuration file as you are giving anyway long absolute path to open office files.

Do the command first from command line. I think you should have each line of code quoted or alternatively pass the name of script file. I also do not see much benefit from this compared to saving the paths to configuration file as you are giving anyway long absolute path to open office files.

Thank you, but I am still rather confused. The OpenOffice install creates a Python folder for core-2.6, but I have 2.7. So, even if I set the path variables manually do I still have to run the OpenOfice version of the Python.exe?

I did re-run the import_uno() code after correcting the path to OO's Python.exe but now I get this error

File "C:\Python27\stan\ImportUNO.py", line 47, in import_uno
    os.environ['UNO_PATH'] = environment_variables[1]                   #4
IndexError: list index out of range

I will mark this as solved, but with frustration. It seems that OpenOffice 3.3 is compiled to work with Python 2.6 - additionally, you cannot run OO's python.exe as the 26 dll is missing. I can see why open-source is so hard on newcomers. But not to throw the baby out with the bathwater, OO does have a COM component -meaning you can

oSM = CreateObject("com.sun.star.ServiceManager")
oDesk= oSM.createInstance("com.sun.star.frame.Desktop")
oBaseContext = oSM.createInstance("com.sun.star.sdb.DatabaseContext")

use code like this from COM enabled scripting langauages (Windows) to manipulate OpenOffice. Again, I'm new at this but perhaps there is a Makepy workaround for ActivePython 2.7

The answer is yes. The OpenOffice COM bridge works very well with ActivePython (version independent).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.