PYTHON

Python 2.7 installing opencv via pip (virtual environment)

Remoted remoted 2021. 5. 10. 12:18

VSCode 환경에서 OpenCV 를 설치할 때 꼭 문제되는 사항이 있다.

 왠지 심리적인 느낌으로 반드시 에러가 날 거라고 생각하긴 했지만 진짜 날 줄은 몰랏다.

 

다음과 같은 문제가 발생할 수 있다.

python -m pip install --upgrade pip
python -m pip install opencv-python

 

위에서 python -m 이 없는 경우에, 즉 pip 만을 이용해서 Library Module 을 import 때리려고 하는데

인식을 못하는 것이다.

 

더 큰 문제는 위와같이 때려도 문제가 나는 경우가 있는데, 그 경우에는 머리털이 곤두서게 된다.

 

(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.

 

나랑 완전 100% 같은 경우는 아닌데, 이분은 path 가 root 부터 시작하는 걸 보니 리눅스의 냄새다

 

거기다 가장 큰 단서는 _in_process.py 에서 롤린하다가 에러가 낫다는건데, ㅇ ㅣ부분에서 답변을 살펴보면

 

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.

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:

 

버전이 맘에 안든다는 이야기다

 

python -m pip install opencv-python==4.2.0.32

이렇게 해줫더니 깔끔하게 됫다.

 

stackoverflow.com/questions/63346648/python-2-7-installing-opencv-via-pip-virtual-environment

 

 

 

아! 추가적으로 혹시 모르니까

setting.json 에서 한줄 추가해준다.

"python.linting.pylintArgs": ["--extension-pkg-whitelist=cv2"] 

 

1 2 3 4 5 ··· 9