【问题标题】:numpy import fails when Python is embedded in C++当 Python 嵌入 C++ 时,numpy 导入失败
【发布时间】:2013-01-11 15:50:49
【问题描述】:

使用嵌入到我的 C++ 应用程序(32 位)并静态链接的 Python 2.7 访问 numpy 时遇到问题。在我的应用程序可执行文件下,我将 python27.dll 与 Python27 目录以及所有需要的 DLL 一起放置。我还在单独的文件夹 (C:\Python27) 中安装了 Python 2.7 和 numpy(均为 32 位)。当我运行我的应用程序并尝试导入 numpy 时,我收到以下错误:

Traceback (most recent call last):
File "pytest", line 1, in <module>
    File "C:\Python27\lib\site-packages\numpy\__init__.py", line 137, in <module>
    import add_newdocs
    File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
    File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
    from type_check import *
    File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 8, in <module>
    import numpy.core.numeric as _nx
    File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 5, in <module>
    import multiarray
ImportError: DLL load failed: The specified module could not be found.

当我从我的应用程序文件夹中删除 python27.dll 时,我可以导入 numpy。当客户想要导入任何 Python 第三方库时,我不能要求客户手动删除 python27.dll ......有人对我如何解决这个问题有想法吗?这个多数组模块是怎么回事?

【问题讨论】:

    标签: c++ python numpy


    【解决方案1】:

    好的,问题解决了。嵌入式应用程序文件夹下的 python27.dll 文件必须与 Python 2.7 版本相同。验证日期以确保它们相同。如果它们不一样,您可能会遇到各种问题。

    My Application Folder
        myApp.exe
        python27.dll  <-- must be the same as Python installed on your machine
        Python27 Folder
            DLL
            Libs
    

    【讨论】:

    • 这暗示了一个部署起来可能很混乱的设置。指示性,嵌入式 python 解释器位于单独的位置,并尝试使用作为系统安装的一部分安装的 numpy 包。然而,如果你希望将它作为一个包提供,嵌入式解释器和所有相关包(包括 numpy)应该放在一起。
    猜你喜欢
    • 2012-11-13
    • 2020-03-11
    • 2021-03-29
    • 1970-01-01
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    相关资源
    最近更新 更多