Python 2.7 通过pip(虚拟环境)安装opencv [英] Python 2.7 installing opencv via pip (virtual environment)

查看:167
本文介绍了Python 2.7 通过pip(虚拟环境)安装opencv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在虚拟环境 (Python 2.7) 中通过 pip 安装 opencv-python 包.不幸的是,我收到一个错误:

I'm trying to install opencv-python package via pip inside virtual environment (Python 2.7). Unfortunately, I'm getting an error:

(venv) $ pip2 install opencv-python
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
Collecting opencv-python
  Using cached opencv-python-4.3.0.38.tar.gz (88.0 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /home/pc_user/.venvs/venv/bin/python /home/pc_user/.venvs/venv/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmp7q7z4L
       cwd: /tmp/pip-install-C21PKF/opencv-python
  Complete output (22 lines):
  Traceback (most recent call last):
    File "/home/pc_user/.venvs/venv/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
      main()
    File "/home/pc_user/.venvs/venv/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/home/pc_user/.venvs/venv/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 114, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/tmp/pip-build-env-2FzygL/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 146, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "/tmp/pip-build-env-2FzygL/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 127, in _get_build_requires
      self.run_setup()
    File "/tmp/pip-build-env-2FzygL/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 243, in run_setup
      self).run_setup(setup_script=setup_script)
    File "/tmp/pip-build-env-2FzygL/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 142, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 448, in <module>
      main()
    File "setup.py", line 99, in main
      % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
    File "/usr/lib/python2.7/re.py", line 210, in escape
      s = list(pattern)
  TypeError: 'NoneType' object is not iterable
  ----------------------------------------
ERROR: Command errored out with exit status 1: /home/pc_user/.venvs/venv/bin/python /home/pc_user/.venvs/venv/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmp7q7z4L Check the logs for full command output.

我试过新建环境或者通过python2 -m pip install安装,但是效果是一样的.有什么问题?

I've tried to create a new environment or installing through python2 -m pip install but the effect is the same. What's the problem?

推荐答案

opencv-python-4.3.0.38 不再支持 Python 2.7.4.3.0.36 不再支持;请参阅此问题.

Python 2.7 is not supported anymore in opencv-python-4.3.0.38. Support was dropped in 4.3.0.36; see this issue.

我发现的解决方法是安装 opencv-python 版本 4.2.0.32(这是 Python 2.7 支持的最新版本,请参阅 this 适用于所有版本)像这样:

The workaround I found was to install opencv-python version 4.2.0.32 (which is the latest supported for Python 2.7, see this for all releases) like this:

pip2 install opencv-python==4.2.0.32

这篇关于Python 2.7 通过pip(虚拟环境)安装opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆