Replacing stock Python

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
zCRP
Posts: 10
Joined: Tue Jan 26, 2010 12:15 am

Replacing stock Python

Post by zCRP »

Hi I am trying to replace the stock supplied Python interpreter with the one I have installed myself.
My config:
OpenOffice 3.1.1 (which comes with Python 2.6.1) on WinXP V2002SP3

I am trying to use Python 2.6.2 so that I can more easily use external IDEs, install different modules etc.

I have tried following instructions from the following page http://udk.openoffice.org/python/python ... #replacing, although they appear to refer to older versions of OO.

So I went and modified Basis\program\pythonloader.uno.ini like this:

Code: Select all

[Bootstrap]
PYUNO_LOADER_PYTHONHOME=c:/Programmi/python
PYUNO_LOADER_PYTHONPATH=c:/Programmi/python/Lib c:/Programmi/python/Lib/site-packages $ORIGIN
then I renamed the old python executables and dll in program, and finally went to cmd.exe, set the PATH and PYTHONPATH envvars, then launched python (2.6.2), but if I type "import uno" I get the error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named uno
Also, I have modified the standard HelloWorld.py macro that comes with OpenOffice so that it prints out sys.version from python. For some reason I still do not grasp, I am told that OO is still running python 2.6.1, even after all the renaming I did of the executables.

Anyone has any suggestions?

Thanks
Chris
OpenOffice 3.1.1 on MacOS 10.6.2
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Replacing stock Python

Post by Villeroy »

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
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Replacing stock Python

Post by hanya »

I tried in my environment:
Python 2.6.4: E:\usr\local\python26 (python26.dll is there)
OOo-dev DEV300m69: E:\usr\local\OOo\Dev69 (installed with /a option)

E:\usr\local\OOo\Dev69\OOo-dev 3\Basis\program\pythonloader.uno.ini

Code: Select all

[Bootstrap]
PYUNO_LOADER_PYTHONHOME=E:/usr/local/python26
PYUNO_LOADER_PYTHONPATH=E:/usr/local/python26/Lib E:/usr/local/python26/Lib/site-packages $ORIGIN
I removed these filed to load correct python.dll:
E:\usr\local\OOo\Dev63\OOo-dev 3\program\python26.dll
E:\usr\local\OOo\Dev63\OOo-dev 3\Basis\program\python26.dll

PATH:

Code: Select all

E:\usr\local\python26
Noe output of sys.version:

Code: Select all

2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Replacing stock Python

Post by Villeroy »

May I ask what's wrong with the OOo's version of Python? Is there really any advantage writing office macros with the latest version?
I have written an extension in Python 2.3 that runs perfectly with all office versions since 1.1 (tested with 1.1.4 until 3.2).
Coding against the latest Python may produce incompatibilities against the vanilla version shipped with OpenOffice.org.
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
zCRP
Posts: 10
Joined: Tue Jan 26, 2010 12:15 am

Re: Replacing stock Python

Post by zCRP »

Thanks, in order to get "import uno" working from a python outside of openoffice, I also had to do the following:

Code: Select all

set PATH=C:\Program Files\OpenOffice.org 3\Basis\program;C:\Program Files\OpenOffice.org 3\URE\bin;C:\Program Files\OpenOffice.org 3\;%PATH%
set URE_BOOTSTRAP=file:///C:/Program%20Files/OpenOffice.org%203/program/fundamental.ini
set PYTHONPATH=C:\Programmi\python\Lib;C:\Programmi\python\Lib\site-packages;C:\Program Files\OpenOffice.org 3\Basis\program;
Tonight I will try the same steps on Mac Os X and post results.

Cheers
Chris
OpenOffice 3.1.1 on MacOS 10.6.2
zCRP
Posts: 10
Joined: Tue Jan 26, 2010 12:15 am

Re: Replacing stock Python

Post by zCRP »

I am not really interested in the latest version of python. But what I would do like is being able to use a version of python which can be comfortably extended with whatever module I wish to throw at it. The stock python 2.6 that comes with snow leopard comes with goodies like easy_install, so adding extra modules is easy and fast. At the same time I can choose whatever ide I wish (ipython, idle etc.)
OpenOffice 3.1.1 on MacOS 10.6.2
Induane
Posts: 28
Joined: Fri Mar 28, 2014 4:49 am

Re: Replacing stock Python

Post by Induane »

Also, there are useful changes from python2.6.1 to 2.6.3 - for instance I have a number of tools that utilize httplib (not to mention the infamous requests library), but they all rely on a feature of httplib.py that doesn't exist until python 2.6.3 and as such my macros explode with errors like: VerifiedHTTPSConnection instance has no attribute '_tunnel_host' - which can be most troublesome. Using Python 2.6 isn't a big deal but it would be nice to at least updated it (not to mention 2.6.1 has some security issues that have been patched. A newer version of 2.6 will be api compatible and more secure. It's not always possible to get people away from a specific version of Office, and as such figuring out a clean way to do this would be nice :)
OpenOffice 3.1 on Windows 7 / LibreOffice 3.6 on Ubuntu 13.10 / LibreOffice 4.1 on Ubuntu 13.10
User avatar
karolus
Volunteer
Posts: 1160
Joined: Sat Jul 02, 2011 9:47 am

Re: Replacing stock Python

Post by karolus »

Hallo

in meantime AOO4 is shipped with the latest Python from 2series (2.7.?)
Libreoffice4.x comes with Python3.3***

***except the LO-packages distributed by several Linux-distros - there is Python linked to SystemPython

Karolus
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Induane
Posts: 28
Joined: Fri Mar 28, 2014 4:49 am

Re: Replacing stock Python

Post by Induane »

Yep, and all that is nice, but if you have clients that require a specific version of OpenOffice, then the newer versions don't do you much good :/
OpenOffice 3.1 on Windows 7 / LibreOffice 3.6 on Ubuntu 13.10 / LibreOffice 4.1 on Ubuntu 13.10
Post Reply