centos7.8环境安装opencv-python

centos7.8环境安装opencv-python

 

# 安装好python3.6.9以后要处理python3命令

# ln -s /usr/local/python-3.6.9/bin/pip3 /usr/bin/pip3
# ln -s /usr/local/python-3.6.9/bin/pip3 /usr/local/bin/pip3
# ln -s /usr/local/python-3.6.9/bin/python3 /usr/local/bin/python3

1.升级系统默认的cmake到3.9.2版本

wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz
tar xf cmake-3.9.2.tar.gz
cd cmake-3.9.2

# 编译的时候需要直接 --prefix=/usr/local 否则编译的时候会报错 CMake Error: Could not find CMAKE_ROOT !!!

./bootstrap --prefix=/usr/local/
make -j 4 && make install

# 验证是否安装成功
# cmake --version
cmake version 3.9.2

2.安装依赖

pip3 install --upgrade setuptools
pip3 install numpy Matplotlib
pip3 install --upgrade pip
pip3 install scikit-build
pip3 install opencv-python

 

最终的安装信息

# pip3 list
Package         Version
--------------- --------
cycler          0.10.0
distro          1.5.0
kiwisolver      1.3.1
matplotlib      3.3.4
numpy           1.19.5
opencv-python   4.5.1.48
packaging       20.9
Pillow          8.1.2
pip             21.0.1
pyparsing       2.4.7
python-dateutil 2.8.1
scikit-build    0.11.1
setuptools      54.2.0
six             1.15.0
wheel           0.36.2

验证 opencv-python安装是否成功

# python3
Python 3.6.9 (default, Sep  5 2019, 20:40:16) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2

 

调试信息
为了方便看报错信息,通过源码安装

cd /usr/local/src
wget https://files.pythonhosted.org/packages/bb/08/9dbc183a3ac6baa95fabf749ddb531bd26256edfff5b6c2195eca26258e9/opencv-python-4.5.1.48.tar.gz
tar xf opencv-python-4.5.1.48.tar.gz
cd opencv-python-4.5.1.48
python3 setup.py install

报错1

Traceback (most recent call last):
  File "setup.py", line 10, in <module>
    import skbuild
ModuleNotFoundError: No module named 'skbuild'

# 解决:

pip3 install scikit-build

# 报错2

CMake Error at CMakeLists.txt:27 (cmake_minimum_required):
  CMake 3.5.1 or higher is required.  You are running version 2.8.12.2


-- Configuring incomplete, errors occurred!
Traceback (most recent call last):
  File "/usr/local/python-3.6.9/lib/python3.6/site-packages/skbuild/setuptools_wrap.py", line 586, in setup
    languages=cmake_languages
  File "/usr/local/python-3.6.9/lib/python3.6/site-packages/skbuild/cmaker.py", line 240, in configure
    os.path.abspath(CMAKE_BUILD_DIR())))

An error occurred while configuring with CMake.

解决方法:
升级cmake

cd /usr/local/src
wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz
tar -zxvf cmake-3.9.2.tar.gz
cd cmake-3.9.2
./bootstrap --prefix=/usr/local/
make -j 4 && make install

报错3

报错3
# 编译安装 opencv-python,方便查看报错信息

# python3 setup.py install

/usr/local/python-3.6.9/lib/python3.6/site-packages/setuptools/dist.py:645: UserWarning: Usage of dash-separated 'index-url' will not be supported in future versions. Please use the underscore name 'index_url' instead
  % (opt, underscore_opt))
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/local/share/cmake-3.6

解决办法:
安装 cmake时指定到 /usr/local 目录即可
./bootstrap --prefix=/usr/local/

posted @ 2021-03-25 13:50  reblue520  阅读(419)  评论(0编辑  收藏  举报