rstudio / reticulate

R Interface to Python
https://rstudio.github.io/reticulate
Apache License 2.0
1.68k stars 328 forks source link

ImportError when importing sklearn #805

Open hypebright opened 4 years ago

hypebright commented 4 years ago

Hi,

I'm running into an issue when trying to import sklearn through reticulate.

I use use_condaenv to point retiulcate to my anaconda python 3.7 installation:

use_condaenv(condaenv = "/opt/anaconda3/envs/python37/", required = TRUE)

and when I try to import sklearn like:

sklearn <- import('sklearn')

I get the following error message:

Error in py_module_import(module, convert = convert) : 
  ImportError: dlopen(/opt/anaconda3/envs/python37/lib/python3.7/site-packages/scipy/linalg/_fblas.cpython-37m-darwin.so, 2): Symbol not found: _main
  Referenced from: /opt/anaconda3/envs/python37/lib/python3.7/site-packages/scipy/linalg/_fblas.cpython-37m-darwin.so
  Expected in: flat namespace
 in /opt/anaconda3/envs/python37/lib/python3.7/site-packages/scipy/linalg/_fblas.cpython-37m-darwin.so

Running sklearn in the same environment on Python directly does not replicate this issue and I can import sklearn just fine. I also have no problem importing other modules, like pandas or scypi individually.

I'm running macOS Catalina 10.15.6, R 4.0.0 and reticulate 1.16.

Can you point me in the direction on how to solve this problem?

kevinushey commented 4 years ago

Sorry, I don't have a good idea of what's wrong here. Some others have reported similar issues:

https://www.statalist.org/forums/forum/general-stata-discussion/general/1537891-failure-of-anaconda-miniconda-python-in-stata-16-1-for-macos https://discourse.paraview.org/t/paraview-internal-python-libraries-are-still-broken/3314

hypebright commented 4 years ago

Sorry, I don't have a good idea of what's wrong here. Some others have reported similar issues:

https://www.statalist.org/forums/forum/general-stata-discussion/general/1537891-failure-of-anaconda-miniconda-python-in-stata-16-1-for-macos https://discourse.paraview.org/t/paraview-internal-python-libraries-are-still-broken/3314

Thanks for the reply. I've found those posts as well, but no luck so far. It's also unexpected that Python can just load sklearn fine. I'm able to run a script with Python, but the same script through reticulate in R is a no go. That's why I thought it might be related to reticulate and how it interacts with Python.

teytaud commented 3 years ago

Same problem here. Everything ok in Python, environment correctly loaded, but the exact same error as you with *darwin.so:

ImportError: dlopen(/Users/oteytaud/miniconda3/envs/scipy/lib/python3.7/site-packages/scipy/linalg/_fblas.cpython-37m-darwin.so, 2): Symbol not found: _main

Beth526 commented 3 years ago

same problem, year later can't find an answer

XiangyunHuang commented 3 years ago

Same problem, I still can't find an answer!

kevinushey commented 3 years ago

Do you see the same issue if you use Python with a virtual environment instead (ie: not Anaconda)?

XiangyunHuang commented 3 years ago

virtualenv is OK!

Do you see the same issue if you use Python with a virtual environment instead (ie: not Anaconda)?