Python 2.7 installing opencv via pip (virtual environment)

Python 2.7OpencvPipVirtualenv

Python 2.7 Problem Overview

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
Collecting opencv-python
  Using cached opencv-python- (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/ 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/", line 280, in <module>
    File "/home/pc_user/.venvs/venv/lib/python2.7/site-packages/pip/_vendor/pep517/", 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/", 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/", 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/", line 127, in _get_build_requires
    File "/tmp/pip-build-env-2FzygL/overlay/lib/python2.7/site-packages/setuptools/", line 243, in run_setup
    File "/tmp/pip-build-env-2FzygL/overlay/lib/python2.7/site-packages/setuptools/", line 142, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "", line 448, in <module>
    File "", line 99, in main
      % {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
    File "/usr/lib/python2.7/", 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/ get_requires_for_build_wheel /tmp/tmp7q7z4L Check the logs for full command output.

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?

Python 2.7 Solutions

Solution 1 - Python 2.7

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

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

pip2 install opencv-python==


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionforqedView Question on Stackoverflow
Solution 1 - Python 2.7funie200View Answer on Stackoverflow