问题描述:提示编译出错(不同的pip/conda/linux版本报的错误不一致)
错误一:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
main()
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py", line 205, in build_wheel
metadata_directory)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 217, in build_wheel
wheel_directory, config_settings)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 202, in _build_with_temp_dir
self.run_setup()
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 254, in run_setup
self).run_setup(setup_script=setup_script)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 145, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 535, in <module>
main()
File "setup.py", line 309, in main
cmake_source_dir=cmake_source_dir,
File "/tmp/pip-build-env-tde8voxz/overlay/lib/python3.6/site-packages/skbuild/setuptools_wrap.py", line 683, in setup
cmake_install_dir,
File "setup.py", line 448, in _classify_installed_files_override
raise Exception("Not found: '%s'" % relpath_re)
Exception: Not found: 'python/cv2/py.typed'
----------------------------------------
ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly
WARNING: You are using pip version 20.3.3; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.
错误二:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 262, in build_wheel
metadata_directory)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 217, in build_wheel
wheel_directory, config_settings)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 202, in _build_with_temp_dir
self.run_setup()
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 254, in run_setup
self).run_setup(setup_script=setup_script)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 145, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 535, in <module>
main()
File "setup.py", line 309, in main
cmake_source_dir=cmake_source_dir,
File "/tmp/pip-build-env-efsyy48d/overlay/lib/python3.6/site-packages/skbuild/setuptools_wrap.py", line 683, in setup
cmake_install_dir,
File "setup.py", line 448, in _classify_installed_files_override
raise Exception("Not found: '%s'" % relpath_re)
Exception: Not found: 'python/cv2/py.typed'
----------------------------------------
ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects
解决方法一:安装build-essential与cmake后,再然后重新安装opencv-python,安装指令如下(若无需使用opencv-python新版本的特定功能,则不推荐使用,因为新版本需要编译安装,编译时间约20分钟左右)
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install build-essential cmake
解决方法二:查看当前未能安装成功的opencv版本,然后指定一个低版本的opencv-python安装(推荐使用,部分低版本安装无需编译,可以瞬间完成安装)文章来源:https://www.toymoban.com/news/detail-755775.html
# 如默认安装的opencv-python版本为4.8,切换4.5版本安装
pip install opencv-python==4.5.1.48
# 注:1、一些低版本的opencv-python不用编译,可以直接安装成功
# 2、版本的详细版本号可以尝试安装后,根据可以选择的版本提示安装
pip install opencv-python==4.5
ERROR: Could not find a version that satisfies the requirement opencv-python==4.3 (from versions: 3.2.0.8, 3.3.0.10, 3.3.1.11, 3.4.0.12, 3.4.0.14, 3.4.1.15, 3.4.2.16, 3.4.2.17,
3.4.3.18, 3.4.4.19, 3.4.5.20, 3.4.6.27, 3.4.7.28, 3.4.8.29, 3.4.9.31, 3.4.9.33, 3.4.10.35,
3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.14.51, 3.4.14.53,
3.4.15.55, 3.4.16.57, 3.4.16.59, 3.4.17.61, 3.4.17.63, 3.4.18.65, 4.0.0.21, 4.0.1.23,
4.0.1.24, 4.1.0.25, 4.1.1.26, 4.1.2.30, 4.2.0.32, 4.2.0.34, 4.3.0.36, 4.3.0.38, 4.4.0.40,
4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48, 4.5.2.52, 4.5.2.54, 4.5.3.56, 4.5.4.58, 4.5.4.60,
4.5.5.62, 4.5.5.64, 4.6.0.66, 4.7.0.68, 4.7.0.72, 4.8.0.74, 4.8.0.76)
ERROR: No matching distribution found for opencv-python==4.5
补充内容:部分低版本安装虽不用编译,但版本号低于4.8的opencv包在VSCode中没有代码提示,因此能安装新版本尽可能安装新版本文章来源地址https://www.toymoban.com/news/detail-755775.html
到了这里,关于Linux系统下python pip/conda安装opencv(opencv-python)编译出错解决方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!