469,602 Members | 1,838 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

ImportError in python 2.5 in C API DLL

Hi,

We are upgrading from Python 2.3 to verion 2.5 and when we recompile
we get ImportError.

To test we took the spam example from the web documentation and
compiled it with Py23 and it imports without a problem. Changing the
libs in visual studio 2008 to point to Py25 and we get:
>>import spam
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named spam
>>>
Would really appreciate any assistance.

H

----------------------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
static PyObject *
spam_system(PyObject *self, PyObject *args)
{
const char *command;
int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
return Py_BuildValue("i", sts);
}
static PyMethodDef PyBSMethods[] = {
{"spam", (PyCFunction) spam_system, METH_VARARGS|METH_KEYWORDS,
"Hi"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
extern "C" {
__declspec(dllexport) void initspam(void)
{
PyObject* module = Py_InitModule("spam", PyBSMethods);
PyObject* d = PyModule_GetDict(module);
}
}
----------------------------------------------------------------------------------------------------------------------
Oct 16 '08 #1
3 2706
On Oct 16, 10:58*am, Henrik <henrik.martens...@googlemail.comwrote:
Hi,

We are upgrading from Python 2.3 to verion 2.5 and when we recompile
we get ImportError.

To test we took the spam example from the web documentation and
compiled it with Py23 and it imports without a problem. Changing the
libs in visual studio 2008 to point to Py25 and we get:
>import spam

Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
ImportError: No module named spam

Would really appreciate any assistance.

H

----------------------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
* * * * * * * * * * * *DWORD *ul_reason_for_call,
* * * * * * * * * * * *LPVOID lpReserved
* * * * * * * * * * * * * * * *)
{
* * return TRUE;}

#ifdef _MANAGED
#pragma managed(pop)
#endif
static PyObject *
spam_system(PyObject *self, PyObject *args)
{
* * const char *command;
* * int sts;
* * if (!PyArg_ParseTuple(args, "s", &command))
* * * * return NULL;
* * sts = system(command);
* * return Py_BuildValue("i", sts);}

static PyMethodDef PyBSMethods[] = {
* * * {"spam", (PyCFunction) spam_system, METH_VARARGS|METH_KEYWORDS,
"Hi"},
* * * {NULL, NULL, 0, NULL} * * * */* Sentinel */};

extern "C" {
* * * __declspec(dllexport) void initspam(void)
* * * {
* * * * * * PyObject* module = Py_InitModule("spam", PyBSMethods);
* * * * * * PyObject* d = PyModule_GetDict(module);
* * * }}

----------------------------------------------------------------------------------------------------------------------
What about the simple stuff like: did you put your dll/pyd file where
python 2.5 can find it? Are you including the correct Python.h, are
you linking against the correct library (python25.lib or
python25_d.lib)? Have you tried debugging with the "python -v" option
(shows import trace messages)?

Matt
Oct 16 '08 #2
Would really appreciate any assistance.

You should change your project to create a .pyd file instead of a .dll
file.

Regards,
Martin
Oct 17 '08 #3
On Oct 17, 1:05*am, "Martin v. Lwis" <mar...@v.loewis.dewrote:
Would really appreciate any assistance.

You should change your project to create a .pyd file instead of a .dll
file.

Regards,
Martin
Ha-ha!

Just rename the DLL to .pyd

H
Oct 17 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Carsten Gehling | last post: by
reply views Thread by M. Lavasani | last post: by
1 post views Thread by nyiann | last post: by
11 posts views Thread by Fred | last post: by
2 posts views Thread by Adam Blinkinsop | last post: by
4 posts views Thread by prashant | last post: by
reply views Thread by Robert Dailey | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.