Cannot easily connect to Python 3 distributed with LibreOffice on Windows

Create issue
Issue #12 new
Johannes Ranke created an issue

I would like to easily connect to the Python interpreter distributed with LibreOffice on Windows, in order to be able to use the Python-UNO bridge from R.

In E:/Program Files/LibreOffice 5/program, I have

-python.exe
-python33.dll
-python-core-3.3.0
 `-bin
   `-python.exe

I first define some paths in R:

lo_path = "E:/Program Files/LibreOffice 5/program"
lo_py = file.path(lo_path, "python.exe")

Then I naively try to connect:

Sys.setenv(PYTHON_EXE= lo_py)
library(PythonInR)

This gives the error about an invalid 'pattern' argument from #7:

Error : .onLoad failed in loadNamespace() for 'PythonInR', details:
  call: grepl(dllName, dir(pyHome), fixed = TRUE)
  error: invalid 'pattern' argument
In addition: Warning message:
package ‘PythonInR’ was built under R version 3.3.2 
Error: package or namespace load failed for ‘PythonInR’

which is caused by the fact that

sysCallPython(pythonExePath, "str(sys.version_info.major)")

in autodetectPython returns NULL. However, it is possible to get the major version number e.g. by

system(paste0("\"", lo_py, "\" -c \"import sys; print(sys.version_info.major)\""))

So maybe sysCallPython needs an improvement to fix #7.

With a bit of trial and error, I found that It is possible to use pyConnectWinDll directly:

PythonInR:::pyConnectWinDll(
  dllName = "python33.dll",
  dllDir = lo_path,
  majorVersion = 3,
  pythonHome = paste0(lo_path, "/python-core-3.3.0"),
  pyArch = "32bit")

so I am documenting that here. It takes a bit more to actually get the Python-UNO bridge up, I have some code for that in https://github.com/jranke/rlo/blob/windows/test_windows.R

Comments (0)

  1. Log in to comment