电脑安装了opencv 3.2,python 3.8.5,anaconda。
但执行python xxx.py
文件时,只要源码中带有import cv2
,那么编译都会报这个错。
解决:
pip install opencv-python
重新安装时,error:
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
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.
Defaulting to user installation because normal site-packages is not writeable
Collecting opencv-pythonUsing cached opencv-python-4.3.0.38.tar.gz (88.0 MB)Installing build dependencies ... doneGetting requirements to build wheel ... errorERROR: Command errored out with exit status 1:command: /usr/bin/python /home/xzx/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpTZYVwqcwd: /tmp/pip-install-MdK4_o/opencv-pythonComplete output (22 lines):Traceback (most recent call last):File "/home/xzx/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>main()File "/home/xzx/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in mainjson_out['return_val'] = hook(**hook_input['kwargs'])File "/home/xzx/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 114, in get_requires_for_build_wheelreturn hook(config_settings)File "/tmp/pip-build-env-QCI1ZZ/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 146, in get_requires_for_build_wheelreturn self._get_build_requires(config_settings, requirements=['wheel'])File "/tmp/pip-build-env-QCI1ZZ/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 127, in _get_build_requiresself.run_setup()File "/tmp/pip-build-env-QCI1ZZ/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 243, in run_setupself).run_setup(setup_script=setup_script)File "/tmp/pip-build-env-QCI1ZZ/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 142, in run_setupexec(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 escapes = list(pattern)TypeError: 'NoneType' object is not iterable----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python /home/xzx/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpTZYVwq Check the logs for full command output.
WARNING: You are using pip version 20.3.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/bin/python -m pip install --upgrade pip' command.
原因: opencv-python-4.3.0.38 不再支持 Python 2.7
解决:pip install opencv-python==4.2.0.32
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
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.
Defaulting to user installation because normal site-packages is not writeable
Collecting opencv-python==4.2.0.32Downloading opencv_python-4.2.0.32-cp27-cp27mu-manylinux1_x86_64.whl (28.2 MB)|████████████████████████████████| 28.2 MB 788 kB/s
Requirement already satisfied: numpy>=1.11.1 in /usr/lib/python2.7/dist-packages (from opencv-python==4.2.0.32) (1.13.3)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.2.0.32
WARNING: You are using pip version 20.3.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/bin/python -m pip install --upgrade pip' command.