473,237 Members | 1,221 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,237 software developers and data experts.

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)



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,


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

00000000000000000000000000000000000000000000000000 000000


%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


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


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


_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):


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,

__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):


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)


class BallScrew(_object):

__swig_setmethods__ = {}

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

__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):


if self.thisown: destroy(self)

except: pass

def SetNonExposeCurrent(*args): return

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)


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

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

Similar topics

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
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...
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...
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 ...
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...
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
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...
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...
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...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.