473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 2932
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. Löwis" <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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carsten Gehling | last post by:
Figured out myself - I just removed the line with "from url import Url" -it doesn't seem to be used anywhere ;-) - Carsten > -----Oprindelig meddelelse----- > Fra:...
2
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
0
by: M. Lavasani | last post by:
Hi I am trying to test Python-2.3. Any solution for this problem please: >>>gmake test case $MAKEFLAGS in \ *-s*)...
1
by: nyiann | last post by:
Hi, Brand new to python. I am trying to install the py2exe modeule, and when I run scripts (simple ones I've made, and examples) I get an importerror. At the python command line I type: import...
11
by: Fred | last post by:
I hope someone can help me with the below problem... Thanks, Fred My enviroment: -------------------------- Slackware Linux 10.2 Python 2.4.2 MySql version 4.1.14
2
by: Adam Blinkinsop | last post by:
I'm writing a set of modules to monitor remote system services, and I'm having a problem running my test scripts. When I pass the scripts into python, like so: -- $ PYTHONPATH="${TARGET_DIR}"...
4
by: prashant | last post by:
I am running a python script which has the line import getopt, sys, os, re, string And i get the error ImportError: No module named getopt Could you please point out a possible solution...
0
by: Robert Dailey | last post by:
I created a basic python file and made an attempt to execute it from the command line, however it gives me a weird error after the python file has been executed: Traceback (most recent call...
1
by: manasonnet | last post by:
ava.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.