pycharm安装opencv-python报错

问题一 通过pycharm中的Terminal窗口安装opencv-python错误如下:

在这里插入图片描述
上图所示为部分错误,全部错误如下:

  Building wheel for opencv-contrib-python (PEP 517) ... error
  ERROR: Complete output from command 'D:\anzhuanglujing\Anaconda\python.exe' 'D:\anzhuanglujing\Anaconda\lib\site
-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\Administrator\AppData\Local\Temp\tmpjqvqd9_8':
  ERROR: Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      Ninja
  
    does not support platform specification, but platform
  
      x64
  
    was specified.
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      Visual Studio 17 2022
  
    could not find any instance of Visual Studio.
  
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      Ninja
  
    does not support platform specification, but platform
  
      x64
  
    was specified.
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      Visual Studio 16 2019
  
    could not find any instance of Visual Studio.
  
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      Ninja
  
    does not support platform specification, but platform
  
      x64
  
    was specified.
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      Visual Studio 15 2017
  
    could not find any instance of Visual Studio.
  
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      NMake Makefiles
  
    does not support platform specification, but platform
  
      x64
  
    was specified.
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      NMake Makefiles
  
    does not support platform specification, but platform
  
      x64
  
    was specified.
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator
  
      NMake Makefiles
  
    does not support platform specification, but platform
  
      x64
  
    was specified.
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Administrator/AppData/Local/Temp/pip-install-bc_r227f/opencv-contrib-python/_cmake_test_compi
le/build/CMakeFiles/CMakeOutput.log".
  
  
  --------------------------------------------------------------------------------
  -- Trying "Ninja (Visual Studio 17 2022 x64 v143)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Ninja (Visual Studio 17 2022 x64 v143)" generator - failure
  --------------------------------------------------------------------------------
  
  
  
  --------------------------------------------------------------------------------
  -- Trying "Visual Studio 17 2022 x64 v143" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Visual Studio 17 2022 x64 v143" generator - failure
  --------------------------------------------------------------------------------
  
  
  
  --------------------------------------------------------------------------------
  -- Trying "Ninja (Visual Studio 16 2019 x64 v142)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Ninja (Visual Studio 16 2019 x64 v142)" generator - failure
  --------------------------------------------------------------------------------
  
  
  
  --------------------------------------------------------------------------------
  -- Trying "Visual Studio 16 2019 x64 v142" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Visual Studio 16 2019 x64 v142" generator - failure
  --------------------------------------------------------------------------------
  
  
  
  --------------------------------------------------------------------------------
  -- Trying "Ninja (Visual Studio 15 2017 x64 v141)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Ninja (Visual Studio 15 2017 x64 v141)" generator - failure
  --------------------------------------------------------------------------------
  
  
  
  --------------------------------------------------------------------------------
  -- Trying "Visual Studio 15 2017 x64 v141" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Visual Studio 15 2017 x64 v141" generator - failure
  --------------------------------------------------------------------------------
  
  
  
  --------------------------------------------------------------------------------
  -- Trying "NMake Makefiles (Visual Studio 17 2022 x64 v143)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "NMake Makefiles (Visual Studio 17 2022 x64 v143)" generator - failure
  --------------------------------------------------------------------------------
  
  
  
  --------------------------------------------------------------------------------
  -- Trying "NMake Makefiles (Visual Studio 16 2019 x64 v142)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "NMake Makefiles (Visual Studio 16 2019 x64 v142)" generator - failure
  --------------------------------------------------------------------------------
  
  
  
  --------------------------------------------------------------------------------
  -- Trying "NMake Makefiles (Visual Studio 15 2017 x64 v141)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "NMake Makefiles (Visual Studio 15 2017 x64 v141)" generator - failure
  --------------------------------------------------------------------------------
  
  ********************************************************************************
  scikit-build could not get a working generator for your system. Aborting build.
  
  Building windows wheels for Python 3.7 requires Microsoft Visual Studio 2022.
  Get it with "Visual Studio 2017":
  
    https://visualstudio.microsoft.com/vs/
  
  Or with "Visual Studio 2019":
  
    https://visualstudio.microsoft.com/vs/
  
  Or with "Visual Studio 2022":
  
    https://visualstudio.microsoft.com/vs/
  
  ********************************************************************************
  ----------------------------------------
  ERROR: Failed building wheel for opencv-contrib-python
  Running setup.py clean for opencv-contrib-python
Failed to build opencv-contrib-python
ERROR: Could not build wheels for opencv-contrib-python which use PEP 517 and cannot be installed directly

解决办法:升级pip版本,命令如下:python -m pip install --upgrade pip

升级后显示如下图所示:
在这里插入图片描述
安装opencv-python,

命令如下:pip install opencv-contrib-python -ihttps://pypi.tuna.tsinghua.edu.cn/simple

安装成功后结果如下图所示:
在这里插入图片描述

问题二用默认源安装库,一般来说下载的速度很慢,更何况opencv这种比较大的库,所以我使用的是豆瓣源(当然你也可以使用清华源…)

安装语句

pip install opencv-python -i https://pypi.doubanio.com/simple/

报错
在这里插入图片描述

解决方案一

遇到这个问题之后,我在网上查阅解决方法,有文章说是需要安装cmake(但是其实没有实际解决,严格按照文章步骤操作,最后将会成功安装opencv)

安装语句
pip install cmake -i https://pypi.doubanio.com/simple/
在这里插入图片描述
以上是cmake安装成功的信息提示

问题再现
当安装完cmake之后,我又重新使用pip安装opencv,但是依旧没能安装成功 😦 依然还是与问题一同样的报错。于是,我又重新查阅网上资料,得到的解决方案是,需要更新pip工具包。

解决方案二

需要修复pip。

修复语句
python -m ensurepip

安装成功后,再重新更新pip工具包

python -m pip install --upgrade pip setuptools wheel

这时候发现pip工具包已经更新成功。

紧接着,再次尝试更新opencv。

pip install opencv-python -i https://pypi.doubanio.com/simple/
发现opencv也已经安装成功!问题解决~ 😃
在这里插入图片描述

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: 如果你在PyCharm安装OpenCV时出现错误,可以尝试以下步骤: 1. 确认你使用的是正确的Python解释器。在PyCharm中,你可以在File -> Settings -> Project -> Project Interpreter中查看。 2. 确认你的PyCharm中已经安装了pip。你可以在PyCharm的Terminal中输入以下命令来检查: ``` pip --version ``` 如果没有安装pip,你可以在Terminal中输入以下命令来安装: ``` python get-pip.py ``` 3. 在PyCharm的Terminal中输入以下命令来安装OpenCV: ``` pip install opencv-python ``` 如果你需要安装其他版本的OpenCV,可以在命令后面加上版本号,例如: ``` pip install opencv-python==3.4.2.16 ``` 注意:在安装OpenCV时可能需要下载一些依赖项,这可能需要一些时间。 如果你仍然遇到问题,可以尝试在Stack Overflow等技术论坛上寻求帮助。 ### 回答2: 在PyCharm安装第三方库时,如果出现报错:无法安装OpenCV,可能是由于以下几个原因: 1. 网络或源的问题:请确保您的网络连接正常,并且PyCharm可以访问互联网。有时,源可能无法访问或未正确配置,可以尝试更换国内的镜像源或检查网络设置。 2. 权限问题:请确保您有足够的权限安装软件包或库。有些操作系统可能需要以管理员身份运行PyCharm才能安装库。 解决此问题的方法如下: 1. 检查网络连接:确保您的网络连接正常,可以尝试在浏览器中打开网页确认网络正常。 2. 更换镜像源:使用国内的镜像源可以提高安装速度并解决一些网络访问问题。在PyCharm中,可以打开设置(Settings)窗口,进入"Project: your_project_name"下的"Python Interpreter"选项卡,点击右上角的齿轮图标打开设置,选择"Show All",在安装包列表中,选择需要安装的包,在"Available Packages"下方的镜像源部分,选择合适的镜像源,点击"Install Package"安装。 3. 使用命令行安装:有时,命令行安装库可能更加稳定。可以在PyCharm中打开终端(Terminal)窗口,使用pip命令尝试手动安装OpenCV。在终端窗口中输入以下命令安装OpenCV: ```bash pip install opencv-python ``` 4. 确认PyCharm权限:如果您使用的是Linux或Mac系统,请确保以管理员身份运行PyCharm。在终端窗口中输入以下命令以管理员身份运行PyCharm: ```bash sudo pycharm ``` 以上是一些常见的解决方法,希望能帮助您成功安装OpenCV库。如果问题仍然存在,建议您查阅PyCharm的官方文档或向相关论坛或社区提问以获得更详细的帮助。 ### 回答3: 在使用PyCharm安装第三方库时,遇到报错可能是由于以下几个原因: 1. 网络连接问题:首先确认网络连接正常,因为PyCharm安装库时需要从互联网下载相应的文件。可以尝试使用其他网络连接或重启网络设备来解决问题。 2. PyCharm配置问题:检查PyCharm的环境设置,确保相关路径和配置正确。可以在PyCharm的设置中找到Project Interpreter,确认解释器的路径是否正确,并重新配置路径或添加相应的库。 3. 权限问题:如果PyCharm没有足够的权限来安装库文件,可能会导致报错。使用管理员账户或以管理员身份运行PyCharm,可以解决此问题。 针对安装opencv时出现的报错,可以尝试以下解决方案: 1. 检查网络连接:确认网络连接正常,确保PyCharm可以访问互联网。 2. 检查库名拼写:检查是否正确输入了库的名称,应该是"opencv"而不是拼写错误。 3. 检查环境配置:在PyCharm的设置中,检查Project Interpreter路径是否正确配置。如果没有安装opencv库,则需要在此处安装。 3. 使用命令行安装:可以尝试使用命令行工具在PyCharm的虚拟环境中安装opencv库。打开PyCharm的终端,运行以下命令进行安装: ``` pip install opencv-python ``` 这会尝试从PyPI(Python Package Index,Python软件包索引)下载并安装所需的库文件。 如果以上解决方案无效,可以尝试搜索相关错误信息以获取更多具体的解决方案。另外,确保按照官方文档或可靠教程进行操作,以获得最佳实践和正确的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值