1
votes

Problem

I'm starting to learn machine learning, one of the course examples uses scikit-learn package, and we are required to install and apply what we have done so far. However, I tried to install the package like the course instructor suggested by pip install scikit-learn during the installation, numpy, scipy, threadpoolctl, and joblib were installed as a prerequisite for scikit-learn. So far so good and everything were installed smoothly. But, after that, when I try to import the scikit-learn package like

from sklearn.tree import DecisionTreeRegressor

I get the following error:

  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\hema-\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sklearn\__init__.py", line 74, in <module>
    from .base import clone
  File "C:\Users\hema-\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sklearn\base.py", line 20, in <module>
    from .utils import _IS_32BIT
  File "C:\Users\hema-\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sklearn\utils\__init__.py", line 18, in <module>
    from scipy.sparse import issparse
  File "C:\Users\hema-\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\__init__.py", line 136, in <module>
    from . import _distributor_init
  File "C:\Users\hema-\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\_distributor_init.py", line 61, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2288.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

The case is not only for the above import line, even if I try to import sklearn only I get the same error.

After some research and as it's recommended by the package page, I've used a separate venv and install the package there along with it's dependencies to avoid conflicts. Unfortunately, I'm still getting the same error:

 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Machine Learning\ml_demo\machine_learning_env\lib\site-packages\sklearn\__init__.py", line 80, in <module>
    from .base import clone
  File "D:\Machine Learning\ml_demo\machine_learning_env\lib\site-packages\sklearn\base.py", line 21, in <module>
    from .utils import _IS_32BIT
  File "D:\Machine Learning\ml_demo\machine_learning_env\lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
    from scipy.sparse import issparse
  File "D:\Machine Learning\ml_demo\machine_learning_env\lib\site-packages\scipy\__init__.py", line 136, in <module>
    from . import _distributor_init
  File "D:\Machine Learning\ml_demo\machine_learning_env\lib\site-packages\scipy\_distributor_init.py", line 61, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2288.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

What else did I try?

  • I tried reinstalling.
  • I also tried installing the wheel version of the packages downloaded from here. However, another problem arose, which is when I try installing the wheel by pip install scikit_learn-0.23.1-cp39-cp39-win_amd64.whl I get the following error:
 ERROR: scikit_learn-0.23.1-cp39-cp39-win_amd64.whl is not a supported wheel on this platform.

I did solve this problem nonetheless, by using the --no-binary option as it's stated here.

My environment

  • I'm using Python 3.7.8
  • OS Windows10
  • A list of the venv packages (thought might help)

joblib 0.16.0
numpy 1.19.1
pip 20.1.1
scikit-learn 0.23.1
scipy 1.5.2
setuptools 47.1.0
threadpoolctl 2.1.0

2

2 Answers

0
votes

First, you should enter this code in your shell,Check if your pip version does not support cp39.

import pip._internal;print(pip._internal.pep425tags.get_supported())

Maybe you will get some resonpes, something like this:

[('cp38', 'cp38m', 'win_amd64'), ('cp38', 'none', 'win_amd64'), ('py3', 'none', 'win_amd64'), ('cp38', 'none', 'any'), ('cp3', 'none', 'any'), ('py38', 'none', 'any'), ('py3', 'none', 'any'), ('py37', 'none', 'any'), ('py36', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]

So,If your python pip does not support cp39, then please choose a downgrade version. Forexample:

scikit_learn‑0.23.2‑cp38‑cp38‑win_amd64.whl

And then, When you downloaded this profile,copy to your site-page, Use this command in your Terminal.

pip install scikit_learn‑0.23.2‑cp38‑cp38‑win_amd64.whl

i think it will be working! Hope to help you!

0
votes

Scikit-learn 0.20 was the last version to support Python 2.7 and Python 3.4. Scikit-learn 0.21 supported Python 3.5-3.7. Scikit-learn 0.22 supported Python 3.5-3.8. Scikit-learn now requires Python 3.6 or newer.

So i think you should update your python upto 3.9