user3124318
user3124318

Reputation: 13

Why can't I import scikit-learn from Spyder, but I can import it from the command line?

I installed Spyder 5 for MacOS Big Sur using the standalone installer on the Spyder website (i.e., no Anaconda required). I had been using Spyder 4.2.1 and successfully importing scikit-learn. However, after I installed Spyder 5, I couldn't import scikit-learn, and got a ModuleNotFound error. So I removed the "sklearn" directory from the "Library/Python/2.7/lib/python/site-packages" directory where it was placed, and re-installed scikit-learn with

pip install -U scikit-learn 

as it says on the scikit-learn website. I can now import the module from my Mac's terminal command line, but when I try on Spyder, I get a long message that includes

ImportError: dlopen(/Users/my_user_name/Library/Python/2.7/lib/python/site-packages/sklearn/__check_build/_check_build.so, 2): Symbol not found: __PyThreadState_Current Referenced from: /Users/my_user_name/Library/Python/2.7/lib/python/site-packages/sklearn/__check_build/_check_build.so Expected in: flat namespace in /Users/my_username/Library/Python/2.7/lib/python/site-packages/sklearn/__check_build/_check_build.so

as well as

It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget to build the package before using it: run python setup.py install or make in the source directory.

If you have used an installer, please check that it is suited for your Python version, your operating system and your platform.

What can I do at this point?

Upvotes: 0

Views: 2369

Answers (1)

Seyed_Ali_Mohtarami
Seyed_Ali_Mohtarami

Reputation: 1164

you need install Dependencies : scikit-learn requires:

Python (>= 3.6)

NumPy (>= 1.13.3)

SciPy (>= 0.19.1)

joblib (>= 0.11)

threadpoolctl (>= 2.0.0)

for good result requirements.txt

Note:Scikit-learn 0.20 was the last version to support Python 2.7 and Python 3.4. scikit-learn 0.23 and later require Python 3.6 or newer.

pip install scikit-learn==0.20.4

learn more go to this

Upvotes: 0

Related Questions