# Using openturns from R via reticulate

**URL:** <https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318>\
**Category:** Installation\
**Created:** [September 17, 2023, 12:53pm UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318 "2023-09-17T12:53:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sancelet574](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/sancelet574/32/296_2.png) [@sancelet574](https://openturns.discourse.group/u/sancelet574)\
**Post date:** [September 17, 2023, 12:53pm UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318/1 "2023-09-17T12:53:53Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![MichaelBaudin](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/michaelbaudin/32/9_2.png) [@MichaelBaudin](https://openturns.discourse.group/u/MichaelBaudin)\
**Post date:** [September 18, 2023, 6:41am UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318/2 "2023-09-18T06:41:47Z")

</div>

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

> <https://github.com/openturns/openturns/issues/2360>
>
> Hi! A Windows user sent me the following error:
> 
> \`\`\`
> import openturns as ot
> …
> Traceback (most recent call last):
> File "\<stdin\>", line 1, in \<module\>
> File "C:\\Users\\...\\AppData\\Local\\miniforge3\\lib\\site-packages\\openturns\\\_\_init\_\_.py", line 49, in \<module\>
> from .common import \*
> File "C:\\Users\\...\\AppData\\Local\\miniforge3\\lib\\site-packages\\openturns\\common.py", line 12, in \<module\>
> from . import \_common
> ImportError: DLL load failed while importing \_common: La procédure spécifiée est introuvable.
> \`\`\`
> 
> This user did a fresh install of Miniforge3 for Windows: https://github.com/conda-forge/miniforge/releases/download/23.1.0-3/Miniforge3-23.1.0-3-Windows-x86\_64.exe
> 
> On this fresh install, he ran the command to install openturns and pandas:
> 
> \`\`\`
> conda install openturns pandas
> \`\`\`
> 
> After the install (which reported no error), Pandas could be imported, but OpenTURNS could not (see error message above).

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

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

```

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

---

<div class="post-metadata">

**Author:** ![sancelet574](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/sancelet574/32/296_2.png) [@sancelet574](https://openturns.discourse.group/u/sancelet574)\
**Post date:** [September 18, 2023, 4:29pm UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318/3 "2023-09-18T16:29:27Z")

</div>

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](https://rstudio.github.io/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.

---

<div class="post-metadata">

**Author:** ![MichaelBaudin](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/michaelbaudin/32/9_2.png) [@MichaelBaudin](https://openturns.discourse.group/u/MichaelBaudin)\
**Post date:** [September 23, 2023, 9:52am UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318/4 "2023-09-23T09:52:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sancelet574](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/sancelet574/32/296_2.png) [@sancelet574](https://openturns.discourse.group/u/sancelet574)\
**Post date:** [September 27, 2023, 2:53pm UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318/5 "2023-09-27T14:53:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MichaelBaudin](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/michaelbaudin/32/9_2.png) [@MichaelBaudin](https://openturns.discourse.group/u/MichaelBaudin)\
**Post date:** [October 4, 2023, 12:32pm UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318/6 "2023-10-04T12:32:30Z")

</div>

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:

```python
>>> 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](https://stackoverflow.com/questions/76180354/using-openturns-from-r-via-reticulate)?

---

<div class="post-metadata">

**Author:** ![schueller](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/schueller/32/3_2.png) [@schueller](https://openturns.discourse.group/u/schueller)\
**Post date:** [October 18, 2023, 2:55pm UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318/7 "2023-10-18T14:55:23Z")

</div>

this should be fixed now

---

<div class="post-metadata">

**Author:** ![sancelet574](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/sancelet574/32/296_2.png) [@sancelet574](https://openturns.discourse.group/u/sancelet574)\
**Post date:** [October 18, 2023, 3:13pm UTC](https://openturns.discourse.group/t/using-openturns-from-r-via-reticulate/318/8 "2023-10-18T15:13:43Z")

</div>

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