3

I am trying to run python 3.8 in Rstudio using mac system. However, I am confused about installing modules using reticulate. When I install scipy using py_install("scipy"), I can install it successfully. However, when I test its availability, I got FALSE output, and therefore, I cannot import scipy module.

library(reticulate)
use_python("/usr/local/bin/python3")
py_available() # TRUE
py_install("scipy") # installed sucessfully
py_module_available("scipy") # FALSE

If i use sudo pip install scipy in R terminal, I can successfully install it and import it. Can somebody explain why i cannot install Python module using py_install?

Thanks a lot.

Wang
  • 1,314
  • 14
  • 21
  • If you read the vigentte of py_install, the command "Install Python packages into a virtual environment or Conda environment". So you are always installing into an environment which is separate from your actual python installation (in either conda or /usr/local/bin) – StupidWolf Jan 11 '20 at 21:56
  • You can however use the module scipy after you use py_install – StupidWolf Jan 11 '20 at 21:57
  • @StupidWolf, Thanks for your reply. The problem is that I cannot import the module if i use py_install. – Wang Jan 11 '20 at 21:59
  • I see. Ok I have scipy installed, but lets say we do something like py_install("pygame"); then pygame <- import_from_path("pygame",path='~/.virtualenvs/r-reticulate/lib/python3.7/site-packages/') – StupidWolf Jan 11 '20 at 22:07
  • This should work. You check out the message you get when the package is installed using py_install. Your default path might be different from mine – StupidWolf Jan 11 '20 at 22:08

1 Answers1

1

Maybe this "answer" works for people arriving here based on OP title; works also in jupyter

import os
os.system("pip3 install pandas")

Or:

import subprocess
subprocess.call('pip3 install pytesseract'.split())

or:

import subprocess
subprocess.call(['pip3', 'install', "pandas"])
Ferroao
  • 3,042
  • 28
  • 53