English 中文(简体)
为什么这种从进口到PyRun_SimpleString?
原标题:Why is this from-import failing with PyRun_SimpleString?

我正致力于一个简单(吗)的扎根项目。 我有一套海关包,安装在现场包装中。 c) 安装,例如:

in C:Python27Libsite-packages:

mypackage
    __init__.py
    subpackage
        __init__.py
        subpackage.py
    .... 
    mymodule.py

就在做一些简单的embe事时,我正在得到一些与我打碎玻璃窗时所听到的行为相对应的行为。 具体地说:

PyRun_SimpleString("import mypackage") //Success (return == 0)
PyRun_SimpleString("from mypackage import subpackage") //Success
PyRun_SimpleString("from mypackage import mymodule") //Fail (return == -1)

......如果所有这些工作都只是细微的窗户(无进口商,我可以取得预期结果,例如<代码>dir(金属)

I m aware that the interpreter that results from Py_Initialize() is a little different from what you get in a cmd window, notably sys.path...having read some of the other answers on SO I tried inserting as the first element of sys.path: PyRun_SimpleString("import sys sys.path.insert(0, )") prior to the failing import, but no luck, still returns -1. Also tried appending sys.path with C:Python27Libsite-packagesmypackage , but still no luck importing mymodule (mymodule.py).

根据关于SO和其他地点的其他例子,我曾尝试过几个进口变量,例如:

__import__( mypackage ,globals(), locals(), fromlist=[ mymodule ])
__import__( mypackage.mymodule ,globals(), locals(), fromlist=[ mymodule ])

还尝试了<条码>PyImport_Import ModuleEx,并且与PyRun_SimpleString一样,除“从我的包裹进口ule”外,它还为一切工作。

此外,根据MacOS/Python 2.7,这一设想只是罚款。 它只是视窗,它失败了。

任何可能偏离铁路的想法?

<>UPDATE:一些额外信息:子包装.py 进口一个扩展图书馆(小册子,称其实用性)。 能够进口其他不进口的“快”模块。

最佳回答

抓住难得的机会回答我自己的问题......

一旦我把这个问题缩小到进口公用事业的单元。 延长时间,我用“依赖者”的Walker工具进行了一些挖掘,发现有误装载MSVCR90.DL(没有找到文件)。 在老的几天里,你只能把DLL降低到你的申请道路上,而且通常会奏效。

但是,现在(Vista和之后),它的参与比较少。 阅读 关于一名老的MSVCR DL,我说,我会尝试更新<代码><dependency> section of the expression of my .pyd file to point to point to the same MSVCR90.DL与Adhur27.DLLL, 后者居住在WindowsWinS(边边)的夹。

After that, it worked like a charm. Now I just need to figure out how to automatically include the dependency section during python setup.py mypackage, but that s another question :-)

问题回答

暂无回答




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签