`ImportError: cannot import name _remove_dead_weakref` when importing from scikit learn

DESCRIPTION OF THE PROBLEM

I get this error when calling the python script:

Traceback (most recent call last):
  File "/path/t/file/file.py", line 61, in <module>
    from sklearn.externals import joblib
  File "/anaconda2/lib/python2.7/site-packages/sklearn/__init__.py", line 20, in <module>
    import logging
  File "/anaconda2/lib/python2.7/logging/__init__.py", line 26, in <module>
    import sys, os, time, cStringIO, traceback, warnings, weakref, collections
  File "/anaconda2/lib/python2.7/weakref.py", line 14, in <module>
    from _weakref import (
ImportError: cannot import name _remove_dead_weakref
Failed to load file

As indicated in the error log, this happens when I import:

from sklearn.externals import joblib

NOTES

NOTE 1: call import sklearn also causes this error.

NOTE 2: Running without any other import statements, and the rest of the code in the commented file also causes an error

NOTE 3: Objective-C code calls this python file through the Python C API ( https://docs.python.org/2/c-api/index.html ). This works fine on another machine with exactly the same specifications and OS (see details below).

4: , Python , import sklearn from sklearn.externals import joblib ( objective-C)

5: , . pyenv, pyvenv virtualenv . -bash: pyvenv: command not found

, , MacBook Pro , Mac OS 10.13. ( )

, :

(a) script, (b) CLI python :

print ">>>>>>>>>"+str(sys.executable)
print ">>>>>>>>>"+str(sys.version)
print "++++++++++++++++++++++++++++++++++++++++++++++++++++"
for p in sys.path: 
    print p

script, :

>>>>>>>>>/anaconda2/bin/python
>>>>>>>>>2.7.10 (default, Feb  6 2017, 23:53:20) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
++++++++++++++++++++++++++++++++++++++++++++++++++++
/anaconda2/lib/python27.zip
/anaconda2/lib/python2.7
/anaconda2/lib/python2.7/plat-darwin
/anaconda2/lib/python2.7/plat-mac
/anaconda2/lib/python2.7/plat-mac/lib-scriptpackages
/anaconda2/lib/python2.7/lib-tk
/anaconda2/lib/python2.7/lib-old
/anaconda2/lib/python2.7/lib-dynload
/anaconda2/lib/python2.7/site-packages
/anaconda2/lib/python2.7/site-packages/aeosa
~/Desktop/Test Software/Sources/*****/path/to/.py/file/*****/Classification

:

>>> sys.executable
'/anaconda2/bin/python'

>>> sys.version
'2.7.14 |Anaconda, Inc.| (default, Dec  7 2017, 11:07:58) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]'

>>> for p in sys.path:
...     print p
... 

/anaconda2/lib/python27.zip
/anaconda2/lib/python2.7
/anaconda2/lib/python2.7/plat-darwin
/anaconda2/lib/python2.7/plat-mac
/anaconda2/lib/python2.7/plat-mac/lib-scriptpackages
/anaconda2/lib/python2.7/lib-tk
/anaconda2/lib/python2.7/lib-old
/anaconda2/lib/python2.7/lib-dynload
/anaconda2/lib/python2.7/site-packages
/anaconda2/lib/python2.7/site-packages/aeosa

, , , () .py .

+4
2

, :

conda uninstall scikit-learn

+1

. , , :

  • sudo pip uninstall scikit-learn
  • sudo pip install -U scikit-learn

, : Scikit-learn :

Python (>= 2.7 or >= 3.3) NumPy (>= 1.8.2), SciPy (>= 0.13.3)

.

Note5: pyenv Python 2. virtualenv.

0

Source: https://habr.com/ru/post/1694106/


All Articles