Search code examples
pythonrreticulate

R : install matplotlib in the new Rstudio preview version


I loaded the reticulate package, if it matters.

In a python script in R, the below commands work.

import numpy as np
import pandas as pd 

But this one doesn't

import matplotlib.pyplot as plt

The console says : ModuleNotFoundError: no module named 'matplotlib'

In R's terminal I'm trying to do pip install matplotlib , but I get the error 'pip' is not recognized as an internal or external command, operable program or batch file.


Solution

  • I think you need to use the py_install function provided in the reticulate package.

    It should work: py_install(packages = "matplotlib")

    In case you are using an virtual environment, try the virtualenv_install function.