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

[EDIT]

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.

[/EDIT]

This is based on my initial problem here: Trying to replicate VBA shell functionality...
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\site.py line 173 The relevant line is

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

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 - What’s New In Python 3.0 — Python v3.0.1 documentation

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?

Hallo

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("com.sun.star.system.SystemShellExecute")
# the next line runs interpreter in path "C:\Anaconda\python.exe"
objExec.execute("C:\Anaconda\python.exe", "C:\dummy\out\temp.py", 0)

it seems youre complete out of clue what youre doing!

I see you haven’t read my thread before posting :-p

temp.py 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

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

shell something.bat

or

shell python.exe something.py

or etc.

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

If have read your thread before posting!!

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

no further comment!

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.

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.

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\temp.py", 0)

So this line is going to run your temp.py 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 site.py which is in the python 3 installation.

Have you tried replacing in the line

objExec.execute("C:\Anaconda\python.exe", "C:\dummy\out\temp.py", 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?

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 site.py 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.

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

or

shell something.exe arg1 arg2

and neither of them are working - I’m just getting the Python2 error with site.py

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?