背景
在nvidia ngc平台下载docker image,根据实验要求在环境里安装opencv。因为当前实验tensorflow要求版本较低,我下载了比较久远的版本镜像。如果大家是自己复现代码,还是使用尽可能新的环境,则可以避免大部分环境问题。
问题
通过pip安装opencv,指令如下:
pip install opencv-python
安装过程的输出:
Collecting opencv-python
Downloading https://files.pythonhosted.org/packages/77/f5/49f034f8d109efcf9b7e98fbc051878b83b2f02a1c73f92bbd37f317288e/opencv-python-4.4.0.42.tar.gz (88.9MB)
100% |████████████████████████████████| 88.9MB 919kB/s
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.13.1 in /usr/local/lib/python3.5/dist-packages (from opencv-python) (1.14.5)
Building wheels for collected packages: opencv-python
Building wheel for opencv-python (PEP 517) ...
PEP 517信息出现后,过了很长时间,出现报错信息:
Configuring Project
Working directory:
/tmp/pip-install-zujf20md/opencv-python/_skbuild/linux-x86_64-3.6/cmake-build
Command:
cmake /tmp/pip-install-zujf20md/opencv-python/opencv -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX:PATH=/tmp/pip-install-zujf20md/opencv-python/_skbuild/linux-x86_64-3.6/cmake-install -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python -DPYTHON_VERSION_STRING:STRING=3.6.8 -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python3.6m -DPYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.6m.so -DSKBUILD:INTERNAL=TRUE -DCMAKE_MODULE_PATH:PATH=/tmp/pip-build-env-tr73ewqw/overlay/lib/python3.6/site-packages/skbuild/resources/cmake -DPYTHON3_EXECUTABLE=/usr/bin/python -DPYTHON3_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so -DBUILD_opencv_python3=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_java=OFF -DOPENCV_PYTHON3_INSTALL_PATH=python -DINSTALL_CREATE_DISTRIB=ON -DBUILD_opencv_apps=OFF -DBUILD_opencv_freetype=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_DOCS=OFF -DCMAKE_BUILD_TYPE:STRING=Release
Copying files from CMake output
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py", line 207, in <module>
main()
File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py", line 197, 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 141, in build_wheel
metadata_directory)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 209, in build_wheel
wheel_directory, config_settings)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 194, in _build_with_temp_dir
self.run_setup()
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 237, in run_setup
self).run_setup(setup_script=setup_script)
File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 142, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 496, in <module>
main()
File "setup.py", line 289, in main
cmake_source_dir=cmake_source_dir,
File "/tmp/pip-build-env-tr73ewqw/overlay/lib/python3.6/site-packages/skbuild/setuptools_wrap.py", line 629, in setup
cmake_source_dir, skbuild_kw['cmake_install_dir'])
File "setup.py", line 381, in _classify_installed_files_override
with open('scripts/__init__.py', 'r') as custom_init:
FileNotFoundError: [Errno 2] No such file or directory: 'scripts/__init__.py'
----------------------------------------
ERROR: Failed building wheel for opencv-python
Running setup.py clean 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
解决方案
升级pip工具包:
pip install --upgrade pip setuptools wheel
重试安装:
pip install opencv-python
问题解决啦~!
|