rstudio / reticulate

R Interface to Python
https://rstudio.github.io/reticulate
Apache License 2.0
1.65k stars 326 forks source link

Error: ModuleNotFoundError: No module named 'rpytools' #1570

Open jrausch12 opened 3 months ago

jrausch12 commented 3 months ago

Issue: Error: ModuleNotFoundError: No module named 'rpytools'

Summary: It seems that when using pyenv to manage python versions and having RETICULATE_PYTHON set to the proper pyenv python install location, it prevents reticulate from installing the accompanying rpytools.

Steps to reproduce:

t-kalinowski commented 3 months ago

Hi, thanks for reporting. My guess is that, most likely, this is something specific to your setup. Many people have been using reticulate successfully on Windows with pyenv.

Note that rpytools is not installed in the Python library, it is included in the installed R package, and that location is dynamically placed on the Python path sys.path when reticulate initializes Python.

Do you perhaps have PYTHONPATH set or something similar? What is the output of import sys; print(sys.path)? Is there any additional output shown. Are there any differences if you load python directly, or via reticulate, outside an IDE (e.g., in cmd.exe)?

jrausch12 commented 3 months ago

I do not have PYTHONPATH set. Here's the output of print(sys.path) for a cmd instance which is correctly running 3.10.11 as managed by pyenv

['', 'C:\\Users\\jrauscher\\.pyenv\\pyenv-win\\versions\\3.10.11\\python310.zip', 'C:\\Users\\jrauscher\\.pyenv\\pyenv-win\\versions\\3.10.11\\DLLs', 'C:\\Users\\jrauscher\\.pyenv\\pyenv-win\\versions\\3.10.11\\lib', 'C:\\Users\\jrauscher\\.pyenv\\pyenv-win\\versions\\3.10.11', 'C:\\Users\\jrauscher\\.pyenv\\pyenv-win\\versions\\3.10.11\\lib\\site-packages']

How exactly is reticulate initializing Python? That may give me some clues to potential conflicts with pyenv against local python installations.

t-kalinowski commented 3 months ago

Reticulate inserts rpytools on the Python path here: https://github.com/rstudio/reticulate/blob/9994d8fe295431b0d1ddd0987a72aada03a5403f/R/package.R#L201

Stepping through reticulate:::initialize_python() might reveal why it's not working.

debugonce(reticulate:::initialize_python)
py_eval("1")