Tadashi Nagao
Tadashi Nagao

Reputation: 75

Libreoffice macro how to use external python (not embedde) script througth shell function

Libreoffice macro shell function work fine when shell, PHP or something not python, But shell("x.py") is forced use only embedded python. I want to use external python , maybe some work around exists.

Upvotes: 0

Views: 1811

Answers (2)

Stanislav
Stanislav

Reputation: 11

Here is workaround:

  1. Create bat file with text

    C:\external_python\python.exe my_py.py
    
  2. Run from Basic

    oSvc = createUnoService("com.sun.star.system.SystemShellExecute")
    oSvc.execute(ConvertToUrl("C:\Windows\explorer.exe "),"D:\my_bat.bat", 0)
    

Upvotes: 1

Jim K
Jim K

Reputation: 13790

I assume you are asking about calling from a LibreOffice Basic macro, because Shell is a Basic function. For example, maybe your code looks like:

Sub CallPython
    filepath = "C:\Python33\python.exe C:\OurDocs\x.py"
    Shell(filepath,2)
End Sub

I wonder what "embedded python" version your system is using. To find out, put this code in x.py:

import sys
# change this path to a directory located on your system
with open("c:/users/jimstandard/desktop/x.txt", 'w') as f:
    f.write(sys.version)

To use a different version of Python, use a different path in the filepath variable above.

I often use Python with LibreOffice, but I do not do it this way. Instead, I write macros using PyUNO, which typically does not involve Basic at all. Perhaps this is what you are really trying to do. All of the macro code goes in the Python file, and gets written in Python instead of Basic.

For information on how to use PyUNO, see https://wiki.openoffice.org/wiki/Python.

Upvotes: 2

Related Questions