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的最新版本就可以了。

 

參考:參考一issue


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM