简体   繁体   中英

Unable to Import scikit-learn after installation

I'm trying to use the scikit-learn library in python, but I am completely unable to import it into my python project. I have followed most everything I can find online, but I have close to no idea how to fix this issue.

I created a new python environment, and I tried simply using pip install scipy along with pip install scikit-learn but I couldn't import scipy or scikit-learn successfully. Using the windows binaries , I am able to get scipy working correctly, however the scikit-learn binaries continue to give me an error. The error looks like this:

>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\__init__.py", line 76, in <module>
    from .base import clone
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\base.py", line 16, in <module>
    from .utils import _IS_32BIT
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
    from .validation import (as_float_array,
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\utils\validation.py", line 21, in <module>
    from .fixes import _object_dtype_isnan
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
    from scipy.sparse.linalg import lsqr as sparse_lsqr  # noqa
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\scipy\sparse\linalg\__init__.py", line 113, in <module>
    from .isolve import *
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
    from .iterative import *
  File "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 10, in <module>
    from . import _iterative
ImportError: DLL load failed: The specified module could not be found.

Above the scikit-learn binaries , it says it requires the numpy+mlk module. I tried uninstalling numpy and reinstalling the numpy+mlk binaries with pip, however once I do this, I am no longer even able to import numpy. It gives my a long error message with a link:

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "C:\Users\AdamRice\Documents\DataProcessingServer\scipyContainer\Scripts\python.exe"
  * The NumPy version is: "1.19.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed: The specified module could not be found.

I cannot seem to fix this issue either... most of troubleshooting tactics given on the site don't apply to me, and the ones that do haven't helped. I am working with Python 3.7.9 in Windows 10. Thanks so much!

Figured it out! @yoyoyo helped me by suggesting the conda environment. Conda comes with scipy , scikit-learn , and scikit-image all preinstalled. No headache of installing and importing any of my needed modules with conda.

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