无法打开文件“python310_d.lib”,获取Python Debug 库。

问题原因:

  1. Python Debug 库缺失

  2. 默认情况下,标准 Python 安装(例如 Anaconda)不会附带 Debug 版本的库文件(python310_d.lib)。
  3. 在 Debug 模式下运行 C++ 程序时,MSVC(Microsoft Visual C++ 编译器)会尝试链接带有 _d 后缀的 Python 库(即 Debug 版本),但这个文件通常不存在。

  4. 如果你配置了 Debug 模式,CMake 会假定需要链接 python310_d.lib
  5. 而你实际使用的是 Release 版本的 Python 库(python310.lib),导致链接器无法找到对应的 Debug 库。

               

2.获取_d.lib

生成 Debug 版本库的步骤

1. 下载 Python 源码
  • 从 Python 官方网站 (Index of /ftp/python/Index of /ftp/python/
  • 将python310_d.lib放入debug文件下即可。
  • 正确运行输出:
    Initializing Python…
    Python initialized successfully.
    Importing Python module…
    Python module imported successfully.
    Calling Python function…
    Hello from Python!
    Python finalized.

    作者:kamisama_zhu

    物联沃分享整理
    物联沃-IOTWORD物联网 » 无法打开文件“python310_d.lib”,获取Python Debug 库。

    发表回复