Ask Your Question

Libre office 5 is using python 2 ... how do I fix it?

asked 2016-07-06 15:48:23 +0100

timdp gravatar image

updated 2016-07-07 22:30:14 +0100


For clarity - my question is how to force LibreOffice to use the Python version it is bundled with, as I am getting errors implying it is trying to use a different version of python.

I have found this happens on a lot of computers in my office, so I'd be surprised if no one else experiences it. However it may be that no one else tries to use the shell function extensively.


This is based on my initial problem here: however I found it was caused by a deeper issue.

When I try to run shell commands - I get an error message (however the window vanishes too quickly, so I have to repeat the command multiple times and hit print-screen quickly).

It claims there is an error in C:\Program Files (x86)\LibreOffice 5\program\python-core-3.3.3\lib\ line 173 The relevant line is

            print("Error processing line {:d} of {}:\n".format(n+1, fullname),

The error message claims there is a syntax error on this line, however I would say that this is perfect syntax for python-3. BUT in python 2 this would be a syntax error -

If I add the following line to the start

from __future__ import print_function

then that line no longer gives an error but something else then claims to have a syntax error.

This suggest to me my problem is simply that Libre is running things through python 2 rather than python 3 (I have python 2 installed on my system as the main version, and I don't want to change it for numerous reasons).

Has anyone seen something like this, and knows how to change which version of python is being used?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-07-08 13:30:44 +0100

peterwt gravatar image

I have read this and your linked post.
You state that you have python 2 installed on your system and I assume from the line below it is installed in C:\Anaconda\python.exe.

objExec.execute("C:\Anaconda\python.exe", "C:\dummy\out\", 0)

So this line is going to run your using your python 2 whereas you want to run it under python 3 which is part of the LO installation. It is also odd that the error message you get points to the file which is in the python 3 installation.
Have you tried replacing in the line

objExec.execute("C:\Anaconda\python.exe", "C:\dummy\out\", 0)

the location of python 3 in the LO installation instead of C:\Anaconda\python.exe?

I have in the past opened in LO Word ans Excel files which contain VBA code and they have worked OK. When looking at the macro code in these files in LO the lines below are added by LO

Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1

This module attempts to run VBA native code. Are you using this feature?

edit flag offensive delete link more


I have tried running a .bat file which isn't using python at all, and I still get the same error.

I believe the problem is that Libre is trying to run the objExec function through python 2 - and is also trying to use the file in Libre-python 3 installation. Why it's doing this I don't understand.

I don't think me trying to run a shell command pointing at a python exe should change the internal workings of LO. And as I say the error happens when I just do a .bat file.

timdp gravatar imagetimdp ( 2016-07-08 16:09:12 +0100 )edit

I am using the option VBASupport option- I will double check the VBA_moduletype setting.

Ultimately I want to be able to run a command like

shell something.bat arg1 arg2


shell something.exe arg1 arg2

and neither of them are working - I'm just getting the Python2 error with

timdp gravatar imagetimdp ( 2016-07-08 16:10:44 +0100 )edit

Just checked - the options for VBA are specified exactly as you suggest.

I have tested a couple of batch files - some now work if they are very simple e.g.

dir > list.txt

However if I am trying to run a programme written for python 2 (and hence put in a line to call a specific python.exe) the error occurs again. Somehow the shell command must be forcing Libre to use that exe's python?

timdp gravatar imagetimdp ( 2016-07-08 16:37:17 +0100 )edit

answered 2016-07-06 17:27:09 +0100

karolus gravatar image


Youre LO5(on Windows) comes with python 3.x, but youre still running some script through external python2

from your linked thread:

Dim objExec As Object
objExec = createUnoService("")
# the next line runs interpreter in path "C:\Anaconda\python.exe"
objExec.execute("C:\Anaconda\python.exe", "C:\dummy\out\", 0)

it seems youre complete out of clue what youre doing!

edit flag offensive delete link more


I see you haven't read my thread before posting :-p is a very small programme - and yes I could re-write it to work directly from Libre. BUT I have lots of programmes I need to run - some py using custom libraries, and some .exe and some .bat. They ALL worked using the Shell command - but now they don't.

As far as I can tell LO5 should work through the python3 that it comes bundled with. The fact it is trying to run .bat files using python 2 is the problem and not a result of my code

timdp gravatar imagetimdp ( 2016-07-07 13:10:06 +0100 )edit

to be clear - I mean they all used to work with the VBA excel command:

shell something.bat


shell python.exe

or etc.

now not even a simple .bat file that copies a file can be run by the shell command in Libre.

timdp gravatar imagetimdp ( 2016-07-07 13:11:35 +0100 )edit

If have read your thread before posting!!

If youre not able to rewrite youre … and run it directly via embedded python-interpreter you should stop your silly programming … immediately!

no further comment!

karolus gravatar imagekarolus ( 2016-07-07 13:36:02 +0100 )edit

It sounds like you're saying Libre simply isn't capable of replicating the 'shell' command - and hence I either need to re-write everything (even the bits that aren't in python) to work directly from Libra.

I don't have the budget to pay people to do that, it will be cheaper for my organisation to purchase new Excel for each of our run machines.

timdp gravatar imagetimdp ( 2016-07-07 13:57:23 +0100 )edit

As I said in my first post I have lost of various .exe and .py and .bat files that all interact with many different custom applications, and I'm trying to see if it's possible to migrate a system from having Excel control it to using Libre office. While I could technically re-write everything to work directly from Libre. That will be far more costly than buying new copies of Excel.

timdp gravatar imagetimdp ( 2016-07-07 14:01:07 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-07-06 15:48:23 +0100

Seen: 1,183 times

Last updated: Jul 08 '16