0

I am trying to get rgee properly installed for which python is a requirement. I have both an old version of python (2.7) and a new version (3.10) installed on my Mac running Big Sur OS. Installed via homebrew.

I can set the location correctly for python in reticulate using

use_python(Sys.which("python3"))

But when I try something simple like

np <- reticulate::import("numpy", convert = FALSE)

I get the error

Error in py_module_import(module, convert = convert) : 
  ModuleNotFoundError: No module named 'numpy'

Running the same code when using python 2.7 (after restarting r session etc.)

use_python(Sys.which("python"))

works, with warnings of EOL

Warning message:
In py_initialize(config$python, config$libpython, config$pythonhome,  :
  Python 2 reached EOL on January 1, 2020. Python 2 compatability be removed in an upcoming reticulate release.

How can I use the up-to-date version of python and still have reticulate running properly?

Nebulloyd
  • 264
  • 1
  • 9
  • 2
    missing python modules (in your case numpy) are installed via `pip` command. you will need to ensure your python distribution has pip and use it to install numpy. – toppk Sep 19 '22 at 00:23
  • can I use ```py_install("numpy")``` in R? – Nebulloyd Sep 19 '22 at 00:31
  • I have tried the code in comment above and ```pip3 install numpy``` in terminal. After restarting the R session I am still not able to import numpy. Both confirmed installation. – Nebulloyd Sep 19 '22 at 00:42
  • Solved. Needed to use RStudio>preferences>python to select the correct location of python in the python interpreter. All worked after that. – Nebulloyd Sep 19 '22 at 01:06
  • @Nebulloyd I suspect that this question has been asked and answered in the SO or Google universes. Can you do a search and then delete if that is so? If you cannot find a duplicate, then you can provide code and process documentation in an answer. – IRTFM Sep 19 '22 at 02:13
  • you can choose your python environmnet from within reticulate, though this feature broke with reticulate 1.23. so if you want to have a bit more flexibility/multiple python (for example from having both qgis and arcgis installed, or either of them + a standalone python distribution) installations i recommend using reticulate 1.22. – D.J Sep 19 '22 at 06:32

0 Answers0