Search code examples
rstudioreticulate

Reticulate: python311.dll not found but definitely exists


I wanted to try a Python script in RStudio for the first time. The initial setup of reticulate seemed to go smoothly with no errors in the process: Virtual environment 'r-reticulate' successfully created. However, reticulate does not seem to be finding the .dll, although the error shows the correct filepath to it.

When trying to run any Python code (eg print("hi")) I get the error: Error: C:/Users/[user.name]/AppData/Local/anaconda3/python311.dll - The specified module could not be found.

Now, the .dll is definitely at that location python311

I've tried restarting RStudio and using a clean environment, and reinstalled reticulate with devtools::install_github("rstudio/reticulate", force = TRUE) but same issue continues

How can I force reticulate to recognise the dll? Thanks


Solution

  • Try one of the following.

    1. In RStudio, go to Tools -> Global Options -> Python and manually select where your Python interpreter is. Since it appears you have an anaconda setup, make sure to look under the conda environments.

    2. Create an .Renviron file in R's working directory and create a one liner that says RETICULATE_PYTHON = C:/Users/[user.name]/AppData/Local/anaconda3/python.exe (or wherever your python installation is located).

    3. It's been a while since I've installed reticulate, but if I remember correctly it'll create a virtual environment in your default R working directory under .virtualenvs -> r-reticulate. If it's there and step 1 or 2 hasn't worked, try doing step 2 again except set RETICULATE_PYTHON to the python.exe located in that virtual environment.