How to fix reticulate error in RStudio to use python?
Asked Answered
U

2

6

I am receiving an error when trying to use reticulate that says

library(reticulate)
library(tidyverse)
library(janitor)

Sys.setenv(RETICULATE_PYTHON = "C:/Users/Menu/Programs/Python 3.10.exe")

My Python 3.10 is located in C:/Users/Menu/Programs/Python 3.10.exe

Error in system2(command = python, args = shQuote(config_script), stdout = TRUE,  : 
  '""C:/Users/Menu/Programs/Python 3.10.exe""' not found

When I type in the command prompt:

>>>where python.
C:\Users\AppData\Local\Microsoft\WindowsApps\python.exe
Uitlander answered 6/4, 2022 at 23:34 Comment(2)
So have you tried the obvious? Sys.setenv(RETICULATE_PYTHON = "C:\Users\AppData\Local\Microsoft\WindowsApps\python.exe") I admit that as a Linux user I can never keep straight how Windows handles its directory separators. So maybe use: C:/Users/AppData/Local/Microsoft/WindowsApps/python.exe which is what it might be on a Linux box.Sextet
Yes I tried that and it gives the same error. It is weird because I have python installed on my computer.Uitlander
U
7

I am answering my own question. I was able to figure out how to find the correct path that wasn't showing up in my cmd for some reason.

Type this in R:

reticulate::conda_list()

It will print out all the paths that conda is listed.

Output:

name                                                    python
1 r-miniconda C:\\Users\\AppData\\Local\\r-miniconda\\python.exe
2   anaconda3                   C:\\Users\\anaconda3\\python.exe

Then I added the following

Sys.setenv(RETICULATE_PYTHON = "C:\\Users\\anaconda3\\python.exe")

It worked!

Uitlander answered 7/4, 2022 at 0:17 Comment(1)
Bravo. I like this sort of self answered question. Even better would be to cite the resources with links used to come up with this strategy: Specific help pages? Tutorials? Installation manuals?Sextet
G
0

I have the same kind of problem, however the trick does not work for me:

> library(reticulate)
Error in Sys.setenv(PATH = new_path) : wrong length for argument
In addition: Warning message:
package ‘reticulate’ was built under R version 4.0.5
> conda_list()
name                                 python
1 base C:\\Program Files\\python39/python.exe

Then I restarted R and did the following

Sys.setenv(RETICULATE_PYTHON = "C:\\Program Files\\python39/python.exe")
library(reticulate)

which was followed by the same error message.

Any help would be appreciated.

Cheers Renger

Gallego answered 11/6, 2022 at 16:18 Comment(6)
Do you have Anaconda Navigator installed on your machine? Try installing anaconda then using python.exe inside of conda.Uitlander
No, I have a Python 3.9 installed by the departement. I can't install programms on my own.Gallego
I had that same issue. I had to submit a ticket with IT to upgrade.Uitlander
Unfortunately, that is not an option here. We are stuck with this version another year.Gallego
Try setting python instead of conda_list(): use_python("C:\\Program Files\\python39/python.exe") Documentation:rstudio.github.io/reticulate/articles/….Uitlander
I got the same error message: reticulate::use_python("C:\\Program Files\\python39\\python.exe") Error in Sys.setenv(PATH = new_path) : wrong length for argumentGallego

© 2022 - 2025 — McMap. All rights reserved.