473,505 Members | 14,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SWIG/IDLE/Python: F5 SHIP.py works but "import SHIP" gives "ImportError: dynamic module does not define init function (initSHIP)"

I am working with MSVC6 on Windows XP.

I have created an MSVC project called SHIP

I have a file SHIP.i with "%module SHIP" as the first line (file is below).

I run SHIP.i through SWIG 1.3.24 to obtain SHIP_wrap.cpp and SHIP.py; the
latter contains the line "import _SHIP".

I compile SHIP_wrap.cpp and a bunch of files into a DLL which I have the
linker place in _SHIP.pyd and all goes well.

I start IDLE (version 1.1.1, with Python 2.4.1)

If I open SHIP.py in an edit window and run it (using F5) it runs and if I
do >>> _SHIP.__dict__.keys() I get a load of function names which are like
the ones I'd expect (new_BallScrew for example, where BallScrew is one of my
classes [and is the interface class to the thing I am really interested in
which is already called BallScrewC, before you ask]).

Then I can do things like:
bs = BallScrew(0) bs.Stop() del bs


They work fine. Except of course I really want to put all that stuff in a
script, say test1.py:

import SHIP # This is where my problems begin.

bs = BallScrew(0)

bs.GotoLimit(1)

bs.Stop()

del bs

Which I do and when I run test1.py using F5, the line "import SHIP" in
test1.py produces:

ImportError: dynamic module does not define init function (initSHIP)

So, why can I run SHIP.py straight into Python using F5 but not import it
either directly (>>> import SHIP gives the same error) or indirectly when I
am running another file?

One way round this (though I would like to solve this problem as it will
make things easier as the application grows) is for F5 in IDLE not to
restart the Python interpreter.

My aim is for an engineer to be able to use IDLE to write programs to test
hardware without having to learn C++ to access my OO interface. IDLE and
Python are ideal but I want to make it easy for them to load the interface
(i.e. SHIP) between Python and my OO interface.

Many thanks in advance for any helpful suggestions,

Bill

PS I posted this to sw**@cs.uchicago.edu but it did not seem to get through.

00000000000000000000000000000000000000000000000000 000000

SHIP.i:

%module SHIP

%{

#include "SHIPIF.hpp"

%}

%include "SHIPIF.hpp"

00000000000000000000000000000000000000000000000000 000000

SHIP.py (with no initSHIP L ):

# This file was created automatically by SWIG.

# Don't modify this file, modify the SWIG interface instead.

# This file is compatible with both classic and new-style classes.

import _SHIP

def _swig_setattr_nondynamic(self,class_type,name,valu e,static=1):

if (name == "this"):

if isinstance(value, class_type):

self.__dict__[name] = value.this

if hasattr(value,"thisown"): self.__dict__["thisown"] = value.thisown

del value.thisown

return

method = class_type.__swig_setmethods__.get(name,None)

if method: return method(self,value)

if (not static) or hasattr(self,name) or (name == "thisown"):

self.__dict__[name] = value

else:

raise AttributeError("You cannot add attributes to %s" % self)

def _swig_setattr(self,class_type,name,value):

return _swig_setattr_nondynamic(self,class_type,name,valu e,0)

def _swig_getattr(self,class_type,name):

method = class_type.__swig_getmethods__.get(name,None)

if method: return method(self)

raise AttributeError,name

import types

try:

_object = types.ObjectType

_newclass = 1

except AttributeError:

class _object : pass

_newclass = 0

del types

ToString = _SHIP.ToString

class ObjectCounterC(_object):

__swig_setmethods__ = {}

__setattr__ = lambda self, name, value: _swig_setattr(self, ObjectCounterC,
name, value)

__swig_getmethods__ = {}

__getattr__ = lambda self, name: _swig_getattr(self, ObjectCounterC, name)

def __repr__(self):

return "<%s.%s; proxy of C++ ObjectCounterC instance at %s>" %
(self.__class__.__module__, self.__class__.__name__, self.this,)

def __init__(self, *args):

_swig_setattr(self, ObjectCounterC, 'this', _SHIP.new_ObjectCounterC(*args))

_swig_setattr(self, ObjectCounterC, 'thisown', 1)

def __del__(self, destroy=_SHIP.delete_ObjectCounterC):

try:

if self.thisown: destroy(self)

except: pass

class ObjectCounterCPtr(ObjectCounterC):

def __init__(self, this):

_swig_setattr(self, ObjectCounterC, 'this', this)

if not hasattr(self,"thisown"): _swig_setattr(self, ObjectCounterC,
'thisown', 0)

_swig_setattr(self, ObjectCounterC,self.__class__,ObjectCounterC)

_SHIP.ObjectCounterC_swigregister(ObjectCounterCPt r)

class CallBack(_object):

__swig_setmethods__ = {}

__setattr__ = lambda self, name, value: _swig_setattr(self, CallBack, name,
value)

__swig_getmethods__ = {}

__getattr__ = lambda self, name: _swig_getattr(self, CallBack, name)

def __repr__(self):

return "<%s.%s; proxy of C++ CallBack instance at %s>" %
(self.__class__.__module__, self.__class__.__name__, self.this,)

def __init__(self, *args):

_swig_setattr(self, CallBack, 'this', _SHIP.new_CallBack(*args))

_swig_setattr(self, CallBack, 'thisown', 1)

def __del__(self, destroy=_SHIP.delete_CallBack):

try:

if self.thisown: destroy(self)

except: pass

def SetResult(*args): return _SHIP.CallBack_SetResult(*args)

def GetResult(*args): return _SHIP.CallBack_GetResult(*args)

def Reset(*args): return _SHIP.CallBack_Reset(*args)

def GetReady(*args): return _SHIP.CallBack_GetReady(*args)

class CallBackPtr(CallBack):

def __init__(self, this):

_swig_setattr(self, CallBack, 'this', this)

if not hasattr(self,"thisown"): _swig_setattr(self, CallBack, 'thisown', 0)

_swig_setattr(self, CallBack,self.__class__,CallBack)

_SHIP.CallBack_swigregister(CallBackPtr)

class BallScrew(_object):

__swig_setmethods__ = {}

__setattr__ = lambda self, name, value: _swig_setattr(self, BallScrew, name,
value)

__swig_getmethods__ = {}

__getattr__ = lambda self, name: _swig_getattr(self, BallScrew, name)

def __repr__(self):

return "<%s.%s; proxy of C++ BallScrew instance at %s>" %
(self.__class__.__module__, self.__class__.__name__, self.this,)

def __init__(self, *args):

_swig_setattr(self, BallScrew, 'this', _SHIP.new_BallScrew(*args))

_swig_setattr(self, BallScrew, 'thisown', 1)

def Stop(*args): return _SHIP.BallScrew_Stop(*args)

def __del__(self, destroy=_SHIP.delete_BallScrew):

try:

if self.thisown: destroy(self)

except: pass

def SetNonExposeCurrent(*args): return
_SHIP.BallScrew_SetNonExposeCurrent(*args)

def Move(*args): return _SHIP.BallScrew_Move(*args)

class BallScrewPtr(BallScrew):

def __init__(self, this):

_swig_setattr(self, BallScrew, 'this', this)

if not hasattr(self,"thisown"): _swig_setattr(self, BallScrew, 'thisown', 0)

_swig_setattr(self, BallScrew,self.__class__,BallScrew)

_SHIP.BallScrew_swigregister(BallScrewPtr)

BallScrewCalBackFunction = _SHIP.BallScrewCalBackFunction
Jul 19 '05 #1
0 2684

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17624
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
2
6732
by: Chris Hodapp | last post by:
I have seen messages posted about this before, and there is a clear reference to it in the manual, but I have been unable to find a solution. I'm on Slackware 9.1, kernel 2.6.0-test11, using...
0
2556
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of...
0
2737
by: Bill Davy | last post by:
Hello, I am using SWIG-1.3.24 to make an extension (called SHIP) to Python2.4.1 and then running under IDLE (if that makes any difference) but when I "import SHIP" I get: >>> import SHIP ...
0
1801
by: Terry Tang | last post by:
Hi There, We are extending Python interpreter to support special functions of our tools. What we did is to compile Python's source code (which is got from the an installation on a Linux...
5
2160
by: mark_galeck_spam_magnet | last post by:
Hi, why does complain name 'compileFile' not defined. But works. Why? (I did read the tutorial, it seems to say "import module" should work. Thank you, Mark
1
4336
by: Prof Rodney Coates | last post by:
Although I have been using Macs for a quarter of a century and was doing scientific programming in the '60's I am VERY new to Python on the Mac. I have been writing some very simple applications and...
1
1418
by: smalltalk | last post by:
I have three files names t1.py,t2.py,t3.py in e:\test\dir1,of course dir2 is exsit the content of t1.py as follow: t1.py import os print 'this is t1.py' os.chdir('..\\dir2') the content of...
4
7528
by: Daniel | last post by:
Hello, I'm trying to build a very simple IPC system. What I have done is create Data Transfer Objects (DTO) for each item I'd like to send across the wire. I am serializing these using...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.