【问题标题】:Embed Python Zip file throws error?嵌入 Python Zip 文件会引发错误?
【发布时间】:2016-02-27 06:53:18
【问题描述】:

我正在尝试将 python zip 文件嵌入到我的应用程序中。 我从 python 站点下载了 zip 文件(win32 的)。

这是我用来设置python路径的代码

#include <Python.h>
...
std::wstring exe_dir = L"\\exe\\path";
std::wstring python_path;
python_path += exe_dir + L"python-3.5.1-embed-win32.zip";
Py_SetPath(python_path.c_str());

Py_Initialize(); // Error : "Py_Initialize: unable to load the file system codec"

...

但无论我做什么,应用程序总是抛出相同的错误。 即使我玩各种路径。

如何将 zip 文件嵌入到我的应用中?

【问题讨论】:

    标签: python c++ python-3.x


    【解决方案1】:

    “python-3.5.1-embed-win32.zip”里面还有另一个zip文件

    python35.zip
    

    而那个文件就是需要添加的。

    #include <Python.h>
    ...    
    std::wstring exe_dir = L"\\exe\\path";
    std::wstring python_path;
    python_path += exe_dir + L"python35.zip";
    Py_SetPath(python_path.c_str());
    
    Py_Initialize();    
    ...
    

    我很想知道其他文件的用途,(或者如果这是使用它的正确方法)...

    【讨论】:

    • 我创建了一个blog post,其中包含指向 python 的链接和要遵循的步骤。
    【解决方案2】:

    要回答关于嵌入式发行版中“其他文件的用途”的最后一个问题,您会在某些导入中看到错误。我在导入 NumPy / SciPy 时遇到错误,因为 Python35.zip 之外的其中一个文件丢失了 - _ctypes.pyd。还发现小文件pyvenv.cfg必须至少在 Python 3.5.2 上位于您的 EXE 旁边,这只是一个显示applocal = true 的文本文件。当然你需要python35.dll当然...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2015-12-24
      • 2023-02-02
      相关资源
      最近更新 更多