facebookexperimental / Robyn

Robyn is an experimental, AI/ML-powered and open sourced Marketing Mix Modeling (MMM) package from Meta Marketing Science. Our mission is to democratise modeling knowledge, inspire the industry through innovation, reduce human bias in the modeling process & build a strong open source marketing science community.
https://facebookexperimental.github.io/Robyn/
MIT License
1.08k stars 322 forks source link

Could not import matplotlib.pyplot, - Nevergrad Issue #820

Open Michaelmlewis opened 9 months ago

Michaelmlewis commented 9 months ago

I am trying to install nevergrad via pip using the following library("reticulate") virtualenv_create("r-reticulate") use_virtualenv("r-reticulate", required = TRUE) Sys.setenv(RETICULATE_PYTHON = "C:/Users/MIAT40093/Documents/.virtualenvs/r-reticulate/Scripts/python.exe") py_install("numpy", pip = TRUE) py_install("nevergrad", pip = TRUE)

when I run py_module_available("nevergrad") I get the following error C:\Users\MIAT40~1\DOCUME~1\VIRTUA~1\R-RETI~1\Lib\site-packages\cma\s.py:13: UserWarning: Could not import matplotlib.pyplot, therefore cma.plot() etc. is not available _warnings.warn('Could not import matplotlib.pyplot, therefore' [1] FALSE

Here is my 'py_config() ' python: C:/Users/MIAT40093/Documents/.virtualenvs/r-reticulate/Scripts/python.exe libpython: C:/Users/MIAT40093/AppData/Local/Programs/Python/Python311/python311.dll pythonhome: C:/Users/MIAT40093/Documents/.virtualenvs/r-reticulate version: 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] Architecture: 64bit numpy: C:/Users/MIAT40093/Documents/.virtualenvs/r-reticulate/Lib/site-packages/numpy numpy_version: 1.26.0

NOTE: Python version was forced by RETICULATE_PYTHON

I tried alot of the mentioned solutions, with no luck :(

Would you please advise

gufengzhou commented 9 months ago

Very tricky issue :( reticulate often fails to pick up the right python config by default. Below is my py_config(), as you see I'm using the python libs installed by miniconda.

image

Maybe it's worth trying this out, in the documentation ?reticulate::install_python, you can see the "recommended" Python installation. Just to copy paste the content for easier reference here. I suggest NOT using the latest Python version because I remember reticulate having problems with the latest sometimes.

# In general, it is recommended that Python virtual environments are created using the copies of Python installed by  install_python(). For example:

library(reticulate)
version <- "3.9.12"
install_python(version)
virtualenv_create("my-environment", version = version)
use_virtualenv("my-environment")

# There is also support for a ":latest" suffix to select the latest patch release
install_python("3.9:latest") # install latest patch available at python.org

# select the latest 3.9.* patch installed locally
virtualenv_create("my-environment", version = "3.9:latest")
# Note
# On macOS and Linux this will build Python from sources, which may take a few minutes. Installation will be faster if some build dependencies are preinstalled. See https://github.com/pyenv/pyenv/wiki#suggested-build-environment for example commands you can run to pre-install system dependencies (requires administrator privileges). Python is built with PYTHON_CONFIGURE_OPTS=--enable-shared set.

# On Windows, prebuilt installers from https://www.python.org/ are used.