当需要(但不使用)cv2时,不能从joblib调用非类型

时间:2015-11-25 16:39:06

标签: python-2.7 numpy scikit-learn opencv3.0 joblib

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

最小的失败示例:

setup.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))

tests / __ 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 bug,这就是我去这里的原因。有谁知道这里发生了什么?

一些特点:

  • "cv2"删除install_requires会删除这两个错误
  • 运行Kmeans
  • 的同意
  • 同意没有提供n_jobs的Kmeans。
  • 在错误发布之前打印atexit.registerdelete_folderpool_folder时,其中没有一个是None

如果您无法重现错误,请发表评论:)

1 个答案:

答案 0 :(得分:1)

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

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