0

这个错误很奇怪,每当我在单元测试中使用 n_jobs > 1 的 sklearn 的 Kmeans 并且使用 setuptools 需要 cv2 时,会导致 joblib 调用 None 。

一个最小的失败示例:

设置.py

from setuptools import setup

setup(
    name = "libbla",
# Removing "cv2" resolves the issue :S
    install_requires = ["numpy", "scikit-learn", "cv2"],
    test_suite = 'tests'
)

测试/some_test.py

from sklearn.cluster import KMeans

# also fails without importing sklearn and cv2, just want them for the version numbers.
import unittest, numpy, sklearn, cv2

print("cv2", cv2.__version__)
print("np", numpy.__version__)
print("skl", sklearn.__version__)

class TestFeatureCreator(unittest.TestCase):
    def test_kmeans_2_features(self):
        KMeans(n_clusters = 2, n_jobs = 4).fit_predict(numpy.random.randn(360000, 3))

测试/__init__.py是空的。

然后每当我运行时python2.7 setup.py test,我都会得到以下输出:

$ python2.7 setup.py test
running test
Searching for cv2
Best match: cv2 1.0
Processing cv2-1.0-py2.7.egg

Using /home/herbert/Spyder/bla/.eggs/cv2-1.0-py2.7.egg
running egg_info
writing requirements to libbla.egg-info/requires.txt
writing libbla.egg-info/PKG-INFO
writing top-level names to libbla.egg-info/top_level.txt
writing dependency_links to libbla.egg-info/dependency_links.txt
reading manifest file 'libbla.egg-info/SOURCES.txt'
writing manifest file 'libbla.egg-info/SOURCES.txt'
running build_ext
('cv2', '3.0.0-dev')
('np', '1.10.1')
('skl', '0.16.1')
test_kmeans_2_features (tests.some_test.TestFeatureCreator) ... ok

----------------------------------------------------------------------
Ran 1 test in 1.156s

OK
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.7/dist-packages/joblib/pool.py", line 535, in <lambda>
    atexit.register(lambda: delete_folder(pool_folder))
TypeError: 'NoneType' object is not callable
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.7/dist-packages/joblib/pool.py", line 535, in <lambda>
    atexit.register(lambda: delete_folder(pool_folder))
TypeError: 'NoneType' object is not callable
$

我不确定这是一个 opencv2、sklearn 还是 numpy 错误,这就是我去这里的原因。有人知道这里发生了什么吗?

一些特点:

  • "cv2"从删除install_requires删除两个错误
  • 不跑步的同上Kmeans
  • 没有提供 n_jobs 的 Kmeans 同上。
  • 打印时atexit.registerdelete_folder并且pool_folder就在错误之前,它们都不是None.

当您无法重现错误时也请发表评论:)

4

1 回答 1

1

此问题的修复已合并到 joblib master(将包含在下一个版本 0.10 中):

https://github.com/joblib/joblib/pull/329

于 2016-03-29T13:28:27.937 回答