Python:Ubuntu上使用pip安装opencv-python出现错误
Ubuntu 18.04 上 使用 pip 安装 opencv-python,出现的错误如下:
1 ~$: pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple 2 DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality. 3 Defaulting to user installation because normal site-packages is not writeable 4 Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple 5 Collecting opencv-python 6 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a1/d6/8422797e35f8814b1d9842530566a949d9b5850a466321a6c1d5a99055ee/opencv-python-4.3.0.38.tar.gz (88.0 MB) 7 Installing build dependencies ... done 8 Getting requirements to build wheel ... error 9 ERROR: Command errored out with exit status 1: 10 command: /usr/bin/python /home/litterboy/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmp8E6IcN 11 cwd: /tmp/pip-install-SI_wRI/opencv-python 12 Complete output (22 lines): 13 Traceback (most recent call last): 14 File "/home/litterboy/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module> 15 main() 16 File "/home/litterboy/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main 17 json_out['return_val'] = hook(**hook_input['kwargs']) 18 File "/home/litterboy/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 114, in get_requires_for_build_wheel 19 return hook(config_settings) 20 File "/tmp/pip-build-env-FfK60X/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 146, in get_requires_for_build_wheel 21 return self._get_build_requires(config_settings, requirements=['wheel']) 22 File "/tmp/pip-build-env-FfK60X/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 127, in _get_build_requires 23 self.run_setup() 24 File "/tmp/pip-build-env-FfK60X/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 243, in run_setup 25 self).run_setup(setup_script=setup_script) 26 File "/tmp/pip-build-env-FfK60X/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 142, in run_setup 27 exec(compile(code, __file__, 'exec'), locals()) 28 File "setup.py", line 448, in <module> 29 main() 30 File "setup.py", line 99, in main 31 % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))} 32 File "/usr/lib/python2.7/re.py", line 210, in escape 33 s = list(pattern) 34 TypeError: 'NoneType' object is not iterable 35 ---------------------------------------- 36 ERROR: Command errored out with exit status 1: /usr/bin/python /home/litterboy/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmp8E6IcN Check the logs for full command output.
原因是 opencv-python-4.3.0.38 不再支持 Python 2.7,相关帖子issue。解决办法:
1 pip install opencv-python==4.2.0.32 -i https://pypi.tuna.tsinghua.edu.cn/simple
把 opencv-python 的版本降级到能支持Python 2.7的最新版本就可以了。