简体   繁体   中英

How do I fix this importing error in pycharm?

I recently started using python and pycharm, just to fool around a bit with it. But I am running into a problem with importing the sklearn module. All other modules work just fine, only not this one (sklearn) is a pain. The modules that I try to import are the following:

from sklearn.model_selection import cross_validate
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier as KNeighborsClassifier
from sklearn import svm, neighbors
from sklearn.ensemble import VotingClassifier, RandomForestClassifier

Running this gives the following output:

Traceback (most recent call last):
  File "C:/Users/Luck Slijpen/PycharmProjects/Stock data manipulation/Processing for ML.py", line 5, in <module>
    from sklearn.model_selection import cross_validate
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\sklearn\__init__.py", line 82, in <module>
    from .base import clone
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\sklearn\base.py", line 20, in <module>
    from .utils import _IS_32BIT
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\sklearn\utils\__init__.py", line 27, in <module>
    from .fixes import np_version
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
    import scipy.stats
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\scipy\stats\__init__.py", line 384, in <module>
    from .stats import *
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\scipy\stats\stats.py", line 179, in <module>
    from scipy.spatial.distance import cdist
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\scipy\spatial\__init__.py", line 102, in <module>
    from ._procrustes import procrustes
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\scipy\spatial\_procrustes.py", line 11, in <module>
    from scipy.linalg import orthogonal_procrustes
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\scipy\linalg\__init__.py", line 195, in <module>
    from .misc import *
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\scipy\linalg\misc.py", line 5, in <module>
    from .blas import get_blas_funcs
  File "C:\Users\Luck Slijpen\PycharmProjects\Stock data manipulation\venv\lib\site-packages\scipy\linalg\blas.py", line 215, in <module>
    from scipy.linalg import _fblas
ImportError: DLL load failed: The specified module could not be found.

Process finished with exit code 1

I have been stuck at this for a while and any help is appriciated! Thank you in advance

There is a very high chance this is a PYTHONPATH issue where your pyCharm is unable to talk to the correct python version (or virtual environment) that has all the required libraries installed. You may need to configure pyCharm by going to preferences > project > Project Interpreter and then selecting the correct binary of python

在此处输入图片说明

I would go here: https://scikit-learn.org/stable/install.html Check your installation and re-install if necessary. the site also states that if Numpy or Scipy were recompiled from source (not sure if that is your situation) you may have issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM