如何在Ubuntu上安装PyOpenCV

2 投票
1 回答
3511 浏览
提问于 2025-04-29 08:25

我正在尝试在Ubuntu 14.04上使用setuptools安装PyOpenCV。当我尝试

python setup.py config 

时出现了错误

ImportError: cannot import name Library

我在之前一个问题的回答中发现,解决方法是把

from setuptools import Library  

改成

from setuptools.extension import Library

在setup.py文件中。现在当我运行setup.py时,错误出现在它生成的config.py脚本中:

$ python setup.py config
Configuring PyOpenCV via CMake...
<snip>
-- Configuring done
-- Generating done
-- Build files have been written to:  /home/saul/Downloads/pyopencv/build
Traceback (most recent call last):
File "setup.py", line 137, in <module>
import config as C
File "/home/saul/Downloads/pyopencv/config.py", line 1, in <module>
from setuptools import Extension, Library
ImportError: cannot import name Library

config.py的第一行也有相同的导入错误。当然我可以修正config.py,但我不知道怎么继续构建过程。

setup.py在出错的地方的内容是:

    import config as C

setup(
name = "pyopencv",
version = C.PYOPENCV_VERSION,
description = DOCLINES[0],
author = 'Minh-Tri Pham',
author_email = 'pmtri80@gmail.com',
url = 'http://code.google.com/p/pyopencv/',
license = 'New BSD License',
platforms = 'OS Independent, Windows, Linux, MacOS',
classifiers = filter(None, CLASSIFIERS.split('\n')),
long_description = "\n".join(DOCLINES[2:]),
ext_modules=C.extension_list,
install_requires = ['numpy>=1.2.0'],
package_data = {'pyopencv': ['*.dll']},
include_package_data = True,
# zip_safe = (os.name!='nt'), # thanks to ffmpeg dependency
package_dir={'':'package'},
packages = find_packages('package'),
)

你能告诉我怎么解决这个问题,或者建议一个替代的安装pyOpenCV的方法吗?

暂无标签

1 个回答

7

有一个很简单的方法来做到这一点,打开终端,然后输入:

sudo apt-get install python-opencv

撰写回答