Py_Initialize失败 - 无法加载文件系统编解码器 [英] Py_Initialize fails - unable to load the file system codec

查看:10505
本文介绍了Py_Initialize失败 - 无法加载文件系统编解码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把一个简单的c ++测试项目使用python 3.2。该项目构建正常但Py_Initialize引发一个致命错误:

 致命的Python错误:Py_Initialize:无法加载文件系统编解码器
LookupError:没有编码器搜索功能注册:找不到编码

  #include< Python.h> 

int main(int,char **)
{
Py_Initialize();
Py_Finalize();
return 0;
}

操作系统是32位Vista。



使用的python版本是使用VC ++ 10从源代码生成的python 3.2调试版本。



python_d.exe文件运行时没有任何问题。



有人可以解释这个问题,以及如何解决它?



在浏览python源代码后, ve发现,如错误所示,没有注册编解码器搜索功能。 codec_register PyCodec_Register 是他们应该的。只是在代码中没有任何地方调用这些函数。



我不知道这是什么意思,因为我还不知道什么时候从这些函数应该已经调用。











$ b b $ b

下面回答我自己的问题。

解决方案

因此,由于某种原因,python dll无法找到编码模块。 python.exe可执行文件显然找到它,因为它有预期的相对路径。修改搜索路径的工作原理。



这样做的原因是什么?不知道,但至少它的工作原理。我高度怀疑在某个地方有错字,这通常是奇怪的错误的原因。


I am attempting to put together a simple c++ test project that uses python 3.2. The project builds fine but Py_Initialize raises a fatal error:

Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: no codec search functions registered: can't find encoding

Minimal code:

#include <Python.h>

int main (int, char**)
{
  Py_Initialize ();
  Py_Finalize ();
  return 0;
}

The OS is 32bit Vista.

The python version used is a python 3.2 debug build, built from sources using VC++ 10.

The python_d.exe file from the same build runs without any problems.

Could someone explain the problem and how to fix it? My own google-fu fails me.

[EDIT]

After going through the python source code I've found that, as the error says, no codec search functions have been registered. Both codec_register and PyCodec_Register are as they should be. It's just that nowhere in the code are any of these functions called.

I don't really know what this means as I still have no idea when and from where these functions should have been called. The code that raises the error is entirely missing from the source of my other python build (3.1.3).

[EDIT]

Answered my own question below.

解决方案

So, for some reason the python dll fails to locate the encodings module. The python.exe executable apparently finds it because it has the expected relative path. Modifying the search path works.

The reason for all of this? Don't know but at least it works. I highly suspect a typo on my part somewhere, that's usually the reason for odd bugs it seems.

这篇关于Py_Initialize失败 - 无法加载文件系统编解码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆