在Windows XP上从压缩标准库中嵌入Python 3.3
发布时间:2020-07-16 10:49:24  所属栏目:Windows  来源:互联网 
            导读:我想在我的C应用程序中嵌入 Python 3.3.4,以便: Python的标准库总是从我的应用程序的可执行文件中取出一个zip存档(不应该依赖于任何环境变量等); 我自己的自定义.py模块从可执行文件旁边的另一个文件夹或zip存档导入. 而且,事实上,我几乎成功地做到了.唯一仍
                
                
                
            | 
                         我想在我的C应用程序中嵌入 Python 3.3.4,以便: > Python的标准库总是从我的应用程序的可执行文件中取出一个zip存档(不应该依赖于任何环境变量等); 而且,事实上,我几乎成功地做到了.唯一仍然不起作用的是从ZIP存档导入标准库:它可以作为一个简单的目录工作,但每当我尝试压缩它时,初始化失败并出现以下错误: Fatal Python error: Py_Initialize: unable to load the file system codec 甚至可能使用最新的Python?我已经搜索了很多东西,很多消息来源声称在可执行文件附近放置正确的“python33.zip”应该可行.不过,我的实验证明不然.我错过了什么? 这是我的测试代码 – 由MS Visual Studio 2010制作的最小控制台应用程序,在Windows XP SP3上运行,并对我尝试的内容和结果有一些评论: #include "stdafx.h"
#include "python.h"
int _tmain(int argc,_TCHAR* argv[])
{
    // calling or not calling Py_SetProgramName doesn't seem to change anything
    //Py_SetProgramName(argv[0]);
    // python_lib is a directory with contents of python33/Lib
    // python_lib.zip is an equivalent ZIP archive with contents of python33/Lib (without any top-level subdirs)
    // _scripts.dat is a ZIP archive containing a custom script (hello.py)
    //Py_SetPath(L"python_lib;_scripts.dat"); // works fine! (non-zipped standard library,zipped custom script)
    Py_SetPath(L"python_lib.zip;_scripts.dat"); // both std library and scripts are zipped - fails with error "unable to load the file system codec" during Py_Initialize()
    Py_Initialize();
    PyRun_SimpleString("from time import time,ctimen"
                        "print('Today is',ctime(time()))n");
    PyRun_SimpleString("import hello"); // runs hello.py from inside _scripts.dat (works fine if Py_Initialize succeeds)
    Py_Finalize();
    return 0;
}
 最近在 
 Python Issue 20621中发现并记录了这个问题.它的修复程序将在Python 3.3.5中发布; 3.3.5发布候选人2现在可用于测试. 
 http://www.python.org/download/releases/3.3.5/                        (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
相关内容
- window下使用SetUnhandledExceptionFilter捕获让程序的崩溃
 - Win10远程桌面 出现 身份验证错误,要求的函数不受支持,这
 - gdi – 在Windows 10中带有标题栏的模糊窗口? Windows Upd
 - Windows AD域通过组策略设置域用户登录和注销脚本
 - 在Windows启动时使用参数启动应用程序
 - Windows Phone 7 – 如何在WIndows Phone应用程序中访问Nav
 - Windows:忘记本地账户开机密码,但记得住PIN码
 - 记忆管理 – WinRT是否有垃圾收集?
 - Windows – LogonUser – 来自系统服务的CreateProcessAsUs
 - 在Windows / C上加速Redis#
 
推荐文章
            站长推荐
            - assembly – windows进程内存布局
 - Windows – Win7 Virtualbox在尝试启动虚拟机时出
 - windows下编译支持https的libcurl
 - 我在哪里报告Windows核心库问题?
 - 【问题】no libsigar-amd64-winnt.dll in java.l
 - windows vs2010 下使用glib库 mono4.3
 - office365 – 使用Microsoft Graph API显示即将到
 - windows-phone-7 – Caliburn Micro中的墓碑
 - openstack 填坑笔记4:windows 实例运行出现两个
 - 程序集 – MZ(DOS,16位).EXE标头中页面计数和最后
 
热点阅读
            