ArcPro: installed sklearn but unable to import

586
3
10-19-2021 12:43 PM
KayleighWilson
New Contributor II

Hello, 

I am trying to use sklearn as part of my analysis but I am running into problems importing it. I was able to successfully install scikit-learn (sklearn) into my cloned environment. The installation was successful via the command line with conda, and in the internal Python Package Manager, but both result in the same issue when I try and import sklearn. The strange part is that I am able to successfully import sklearn in my external python command prompt (in the same environment), but I am not able to import it in the python window within ArcPro. I installed the most recent patch, so I am using ArcGIS Pro 2.8.3, Python 3.7.10 [MSC v.1927 64 bit (AMD64)]. 

When I try to import sklearn in the python window within ArcPro, I get this error:

 

 

print(sys.version)
3.7.10 [MSC v.1927 64 bit (AMD64)]
print(sys.prefix)
C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2
import sklearn
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\sklearn\__init__.py", line 82, in <module>
    from .base import clone
  File "C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\sklearn\base.py", line 17, in <module>
    from .utils import _IS_32BIT
  File "C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\sklearn\utils\__init__.py", line 21, in <module>
    from scipy.sparse import issparse
  File "C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\scipy\__init__.py", line 136, in <module>
    from . import _distributor_init
  File "C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\site-packages\scipy\_distributor_init.py", line 59, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

 

 

But when I import sklearn in my external Python Command Prompt there are no issues: 

 

 

(arcgispro-py3-clone2) C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2>python
Python 3.7.10 [MSC v.1927 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.version)
3.7.10 [MSC v.1927 64 bit (AMD64)]
>>> print(sys.prefix)
C:\Users\kwilson\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone2
>>> import sklearn
>>> import scipy
>>>

 

 

The environment and versions are the same as far as I can tell. I tried following the steps from this post but was still unsuccessful: https://community.esri.com/t5/water-resources-questions/archydro-wetland-identification-model-scikit...

Ultimately I would like to be able to use sklearn in Jupyter outside of ArcPro but using the same environment that I set inside ArcPro (in this case: arcgispro-py3-clone2).

I would greatly appreciate any suggestions! Thanks!

0 Kudos
3 Replies
KayleighWilson
New Contributor II

Yes, I activated my environment. I ended up solving the issue by installing sklearn in the python command prompt without updates. First, make sure the environment is activated, then open a python command prompt. Then: 

pip install scikit-learn

 

OgnyanMoore
New Contributor

I'm running into an identical issue with some machines (but not all); was a solution ever found?

0 Kudos