Using openturns from R via reticulate

Hi,

I am trying to use functions from the openturns Python package from R. I believe it should be possible to install and import Python packages using the R-package reticulate , but it does not seem to work for openturns . It seems to work fine for other packages (such as scipy , numpy and pandas ), but I can’t get it to work with openturns . Installing the package seems to work fine but I get an error message when I try to import it. This is what I am doing:

library(reticulate)
use_condaenv("C:/AppsM/Anaconda/")
import("numpy")
Module(numpy)
import("openturns")
Error in py_module_import(module, convert = convert) : 
   ImportError: DLL load failed while importing _common: La procédure spécifiée est introuvable.

Can anyone help?

Many thanks in advance,
Sophie.

Hi Sophie,
There is a bug with numpy and OpenTURNS that was identified lately on Windows:

There is a conda command that can be used to reinstall this:

$ pip install numpy --force-reinstall --no-deps

This is discussed in the topic just below on “Aesara”
Regards,
Michaël

Thank you for your answer Michaël. Nevertheless, using Anaconda Spyder (Windows), I have no problem to install and import OpenTURNS. This works fine.

My problem arises when I try to install and import OpenTURNS using the R-package reticulate that allows to call Python from R (Interface to Python • reticulate). Then, it works for other packages (Scipy, Numpy and Pandas) but not for OpenTURNS with the following error message:

ImportError: DLL load failed while importing _common: La procédure spécifiée est introuvable.

Regards,
Sophie.

Did you try to use the suggested pip command? I am not sure that my message was accurate enough. According to @schueller : "this is due to a conflict with numpy (and scipy) mingw runtime" . This is not related to Spyder.

Regards,
Michaël

Yes, I did it. But, unfortunately, it still doesn’t work…
Regards,
Sophie.

Do you have multiple Python distributions on the system? This may explain why loading OpenTURNS fails from R (which may use the Python distribution A), while you can at the same time load if from Python distribution B. Hence, if the effect of the pip install numpy --force-reinstall --no-deps command is to fix the install in distribution B, this has no effect of install A.
To check this, you can do as follows:

  • from the base Python environment, print the python, numpy and scipy versions ;
  • from Reticulate, print the same versions numbers.

Here is a sample Python code:

>>> import sys
>>> sys.version
'3.9.2 (default, Feb 28 2021, 17:03:44) \n[GCC 10.2.1 20210110]'
>>> import numpy
>>> numpy.__version__
'1.22.1'

Regards,

Michaël
PS
Is there any chance that you asked the same question on Stack at this link?

this should be fixed now

Yes, it works! Thank you very much.
Regards,
Sophie.