首页 > 编程问答 >我无法在我的项目 Pycharm 中导入 opencv-python

我无法在我的项目 Pycharm 中导入 opencv-python

时间:2024-09-24 16:50:17浏览次数:1  
标签:python opencv

(myvenv) PS E:\Python> pip install opencv-python
Collecting opencv-python
  Using cached opencv-python-4.10.0.84.tar.gz (95.1 MB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [66 lines of output]
      Ignoring numpy: markers 'python_version == "3.6" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.7" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.8" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
      Ignoring numpy: markers 'python_version < "3.9" and sys_platform == "linux" and platform_machine == "aarch64"' don't match your environment   
      Ignoring numpy: markers 'python_version < "3.9" and sys_platform == "darwin" and platform_machine == "arm64"' don't match your environment    
      Collecting cmake>=3.1
        Using cached cmake-3.30.3.tar.gz (31 kB)
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Installing backend dependencies: started
        Installing backend dependencies: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'done'
      Collecting numpy>=2.0.0
        Downloading numpy-2.0.2.tar.gz (18.9 MB)
           ---------------------------------------- 18.9/18.9 MB 3.2 MB/s eta 0:00:00
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Installing backend dependencies: started
        Installing backend dependencies: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error

        Preparing metadata (pyproject.toml) did not run successfully.
        exit code: 1

        [23 lines of output]
        + E:\Python\myvenv\bin\python.exe C:\Users\admin\AppData\Local\Temp\pip-install-nzei4sh_\numpy_a368f9e2aa274993be96d795ef79ddd4\vendored-mes
on\meson\meson.py setup C:\Users\admin\AppData\Local\Temp\pip-install-nzei4sh_\numpy_a368f9e2aa274993be96d795ef79ddd4 C:\Users\admin\AppData\Local\T
emp\pip-install-nzei4sh_\numpy_a368f9e2aa274993be96d795ef79ddd4\.mesonpy-cclotgs2 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\admin\AppData\Local\Temp\pip-install-nzei4sh_\numpy_a368f9e2aa274993be96d795ef79ddd4\.mesonpy-cclotgs2\meson-python-native-file.ini     
        The Meson build system
        Version: 1.4.99
        Source dir: C:\Users\admin\AppData\Local\Temp\pip-install-nzei4sh_\numpy_a368f9e2aa274993be96d795ef79ddd4
        Build dir: C:\Users\admin\AppData\Local\Temp\pip-install-nzei4sh_\numpy_a368f9e2aa274993be96d795ef79ddd4\.mesonpy-cclotgs2
        Build type: native build
        Project name: NumPy
        Project version: 2.0.2
        C compiler for the host machine: cc (gcc 12.1.0 "cc (Rev2, Built by MSYS2 project) 12.1.0")
        C linker for the host machine: cc ld.bfd 2.38
        C++ compiler for the host machine: c++ (gcc 12.1.0 "c++ (Rev2, Built by MSYS2 project) 12.1.0")
        C++ linker for the host machine: c++ ld.bfd 2.38
        Cython compiler for the host machine: cython (cython 3.0.11)
        Host machine cpu family: x86_64
        Host machine cpu: x86_64
        Program python found: YES (E:\Python\myvenv\bin\python.exe)
        Found pkg-config: YES (C:\mingw64\bin\pkg-config.EXE) 1.8.0
        Could not find Python3 library 'E:\\Python\\myvenv\\lib\\libpython3.9.dll.a'
        Run-time dependency python found: NO (tried pkgconfig, pkgconfig and sysconfig)

        ..\meson.build:41:12: ERROR: Python dependency not found

        A full log can be found at C:\Users\admin\AppData\Local\Temp\pip-install-nzei4sh_\numpy_a368f9e2aa274993be96d795ef79ddd4\.mesonpy-cclotgs2\meson-logs\meson-log.txt
        [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: metadata-generation-failed

      Encountered error while generating package metadata.

      See above for output.

      note: This is an issue with the package mentioned above, not pip.
      hint: See above for details.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

我设置了cmake并安装了很多次,它仍然无法运行。


根据错误信息,看来问题出在 NumPy 的安装上,而不是 OpenCV 或 CMake 上。错误信息 "Could not find Python3 library 'E:\Python\myvenv\lib\libpython3.9.dll.a'" 表明 NumPy 安装程序找不到你的 Python 环境中的 Python 库文件。

以下是一些可能的解决方案:

  1. 确保你的虚拟环境处于活动状态: 在运行 pip install 命令之前,请确保你已使用 .\myvenv\Scripts\activate 激活了你的虚拟环境。

  2. 升级 pip: 尝试升级 pip 到最新版本: bash python -m pip install --upgrade pip

  3. 手动安装 NumPy: 尝试从 https://pypi.org/project/numpy/#files 下载对应你 Python 版本的 NumPy .whl 文件,然后在你的虚拟环境中使用以下命令安装: bash pip install numpy-*.whl (将 numpy-*.whl 替换为你下载的文件名)

  4. 检查环境变量: 确保你的系统环境变量中包含 Python 安装路径和你的虚拟环境路径。

  5. 重新创建虚拟环境: 尝试删除当前虚拟环境并重新创建一个新的: bash deactivate # 退出当前虚拟环境 rm -rf myvenv # 删除虚拟环境文件夹 python -m venv myvenv # 重新创建虚拟环境 .\myvenv\Scripts\activate # 激活虚拟环境

  6. 使用管理员权限运行: 尝试使用管理员权限运行你的命令提示符或 PowerShell,然后重试安装。

如果以上方法都无法解决问题,请提供以下信息以便我更好地帮助你:

  • 你的操作系统版本
  • 你的 Python 版本
  • 你的 PyCharm 版本
  • 你的 CMake 版本

希望这些信息能帮到你!

标签:python,opencv
From: 79017744

相关文章

  • 如何进行数据清洗?以python和ETL工具为例
    数据清洗是数据分析处理中非常重要的一步,它涉及到识别并处理数据集中的错误或不一致信息,以提高数据质量。数据清洗直接对后续数据处理产生决定性影响,去除重复错误无效的数据能够大大提升数据分析的效率。本文将介绍数据清洗的常用方法和工具,同时以python为例用代码进行数据清洗......
  • 基于Python+Vue开发的蛋糕商城管理系统源码+开发文档
    项目简介该项目是基于Python+Vue开发的蛋糕商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Python编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Python的蛋糕商城管理系统项目,大学生可以在实践中学习和提升自己的能力......
  • 基于Python+Vue开发的旅游景区管理系统源码+开发文档1.3万字
    项目简介该项目是基于Python+Vue开发的旅游景区管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Python编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Python的旅游景区管理系统项目,大学生可以在实践中学习和提升自己的能力......
  • 基于Python+Vue开发的医院门诊预约挂号系统源码+开发文档
    项目简介该项目是基于Python+Vue开发的医院门诊预约挂号系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Python编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Python的医院门诊预约挂号管理系统项目,大学生可以在实践中学习和......
  • 基于Python+Vue开发的音乐推荐管理系统源码+开发文档
    项目简介该项目是基于Python+Vue开发的音乐推荐管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Python编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Python的音乐推荐管理系统项目,大学生可以在实践中学习和提升自己的能力......
  • 基于Python+Vue开发的电影订票管理系统源码+开发文档
    项目简介该项目是基于Python+Vue开发的电影订票管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Python编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Python的电影订票管理系统项目,大学生可以在实践中学习和提升自己的能力......
  • 基于Python+Vue开发的鲜花商城管理系统源码+开发文档
    项目简介该项目是基于Python+Vue开发的鲜花商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Python编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Python的鲜花商城管理系统项目,大学生可以在实践中学习和提升自己的能力......
  • 基于Python+Vue开发的农产品商城管理系统源码+开发文档
    项目简介该项目是基于Python+Vue开发的农产品商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Python编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Python的农产品商城管理系统项目,大学生可以在实践中学习和提升自己的......
  • 熵权法详细讲解+Python代码实现
    ......
  • 计算机专业毕设选题推荐-基于python知识图谱的医疗可视化分析系统
    ......