[Python] Having trouble using Python in R via Reticulate, issue with libraries

Discussão em 'Python' iniciado por Stack, Janeiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am having a hard time getting Python to work in R via Reticulate. I downloaded Anaconda, R, Rstudio, and Python to my system. Below are their paths:

    Python: C:\Users\John\AppData\Local\Microsoft\WindowsApps

    Anaconda: C:\Users\John\anaconda3

    R: C:\Program Files\R\R-4.2.1

    Rstudio: C:\ProgramData\Microsoft\Windows\Start Menu\Programs

    But within R, if I do "Sys.which("python")", the following path is displayed:

    "C:\\Users\\John\\DOCUME~1\\VIRTUA~1\\R-RETI~1\\Scripts\\python.exe"


    Now, whenever I call upon reticulate in R, it works, but after giving the error: "NameError: name 'library' is not defined"

    I can use Python in R, but I'm unable to import any of the libraries that I installed, including pandas, numpy, etc. I installed those in Anaconda (though I used the "base" path when installing, as I didn't understand the whole 'virtual environment' thing). Trying to import a library results in the following error:

    File "
    C:\Users\John\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py
    ", line 122, in _find_and_load_hook
    return _run_hook(name, _hook)
    File "
    C:\Users\John\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py
    ", line 96, in _run_hook
    module = hook()
    File "
    C:\Users\John\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py
    ", line 120, in _hook
    return _find_and_load(name, import_)
    ModuleNotFoundError: No module named 'pandas'


    Does anyone know of a resolution? Thanks in advance.

    Continue reading...

Compartilhe esta Página