将scikit-learn更新到版本0.20.1后出现错误:无法从'queue'导入名称'Empty'

时间:2018-12-19 11:44:58

标签: python scikit-learn anaconda

我从scikit-learn的度量中获取了关于balance_accuracy_score的错误消息后,使用anaconda3将scikit-learn升级到0.20.1版本。这显然在版本0.19中不可用。

此升级后,出现以下错误:

    Traceback (most recent call last):
  File "test4.py", line 4, in <module>
    from sklearn import metrics
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\__init__.py", line 6
4, in <module>
    from .base import clone
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\base.py", line 13, i
n <module>
    from .utils.fixes import signature
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\utils\__init__.py",
line 14, in <module>
    from . import _joblib
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\utils\_joblib.py", l
ine 22, in <module>
    from ..externals import joblib
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\__i
nit__.py", line 119, in <module>
    from .parallel import Parallel
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\par
allel.py", line 28, in <module>
    from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\_pa
rallel_backends.py", line 22, in <module>
    from .executor import get_memmapping_executor
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\exe
cutor.py", line 14, in <module>
    from .externals.loky.reusable_executor import get_reusable_executor
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\ext
ernals\loky\__init__.py", line 13, in <module>
    from .reusable_executor import get_reusable_executor
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\ext
ernals\loky\reusable_executor.py", line 11, in <module>
    from .process_executor import ProcessPoolExecutor, EXTRA_QUEUED_CALLS
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\ext
ernals\loky\process_executor.py", line 82, in <module>
    from .backend.queues import Queue, SimpleQueue, Full
  File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\ext
ernals\loky\backend\queues.py", line 21, in <module>
    from multiprocessing.queues import Full
  File "C:\Users\Pieter\Anaconda3\lib\multiprocessing\queues.py", line 20, in <m
odule>
    from queue import Empty, Full
ImportError: cannot import name 'Empty' from 'queue' (C:\Users\Pieter\Python pro
gs\queue.py)

1 个答案:

答案 0 :(得分:0)

您是否从"C:\Users\Pieter\Python progs"运行此程序?

好像您在queue.py中有一个名为"C:\Users\Pieter\Python pro gs\"的文件,它正在queue lib中的实际模块multiprocessing的阴影下。因此,错误。

有两个可能的原因:

  1. 也许这行:

    from queue import Empty, Full
    

    已添加到新版本中,因此即使存在您自定义的queue.py,它也不会出错。

  2. 也许您在更新scikit-learn之后最近创建了queue.py,并且上面的行始终存在。在这种情况下,两个版本都应该发生错误。

queue.py重命名程序并自动编译queue.pyc 到其他东西,它应该可以工作。