473,703 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SWIG/IDLE/Python: F5 SHIP.py works but "import SHIP" gives "ImportErro r: 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.uchicag o.edu but it did not seem to get through.

000000000000000 000000000000000 000000000000000 00000000000


%module SHIP


#include "SHIPIF.hpp "


%include "SHIPIF.hpp "

000000000000000 000000000000000 000000000000000 00000000000

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_n ondynamic(self, class_type,name ,value,static=1 ):

if (name == "this"):

if isinstance(valu e, class_type):

self.__dict__[name] = value.this

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

del value.thisown


method = class_type.__sw ig_setmethods__ .get(name,None)

if method: return method(self,val ue)

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

self.__dict__[name] = value


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

def _swig_setattr(s elf,class_type, name,value):

return _swig_setattr_n ondynamic(self, class_type,name ,value,0)

def _swig_getattr(s elf,class_type, name):

method = class_type.__sw ig_getmethods__ .get(name,None)

if method: return method(self)

raise AttributeError, name

import types


_object = types.ObjectTyp e

_newclass = 1

except AttributeError:

class _object : pass

_newclass = 0

del types

ToString = _SHIP.ToString

class ObjectCounterC( _object):

__swig_setmetho ds__ = {}

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

__swig_getmetho ds__ = {}

__getattr__ = lambda self, name: _swig_getattr(s elf, 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(s elf, ObjectCounterC, 'this', _SHIP.new_Objec tCounterC(*args ))

_swig_setattr(s elf, ObjectCounterC, 'thisown', 1)

def __del__(self, destroy=_SHIP.d elete_ObjectCou nterC):


if self.thisown: destroy(self)

except: pass

class ObjectCounterCP tr(ObjectCounte rC):

def __init__(self, this):

_swig_setattr(s elf, ObjectCounterC, 'this', this)

if not hasattr(self,"t hisown"): _swig_setattr(s elf, ObjectCounterC,
'thisown', 0)

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

_SHIP.ObjectCou nterC_swigregis ter(ObjectCount erCPtr)

class CallBack(_objec t):

__swig_setmetho ds__ = {}

__setattr__ = lambda self, name, value: _swig_setattr(s elf, CallBack, name,

__swig_getmetho ds__ = {}

__getattr__ = lambda self, name: _swig_getattr(s elf, 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(s elf, CallBack, 'this', _SHIP.new_CallB ack(*args))

_swig_setattr(s elf, CallBack, 'thisown', 1)

def __del__(self, destroy=_SHIP.d elete_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(Cal lBack):

def __init__(self, this):

_swig_setattr(s elf, CallBack, 'this', this)

if not hasattr(self,"t hisown"): _swig_setattr(s elf, CallBack, 'thisown', 0)

_swig_setattr(s elf, CallBack,self._ _class__,CallBa ck)

_SHIP.CallBack_ swigregister(Ca llBackPtr)

class BallScrew(_obje ct):

__swig_setmetho ds__ = {}

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

__swig_getmetho ds__ = {}

__getattr__ = lambda self, name: _swig_getattr(s elf, 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(s elf, BallScrew, 'this', _SHIP.new_BallS crew(*args))

_swig_setattr(s elf, BallScrew, 'thisown', 1)

def Stop(*args): return _SHIP.BallScrew _Stop(*args)

def __del__(self, destroy=_SHIP.d elete_BallScrew ):


if self.thisown: destroy(self)

except: pass

def SetNonExposeCur rent(*args): return
_SHIP.BallScrew _SetNonExposeCu rrent(*args)

def Move(*args): return _SHIP.BallScrew _Move(*args)

class BallScrewPtr(Ba llScrew):

def __init__(self, this):

_swig_setattr(s elf, BallScrew, 'this', this)

if not hasattr(self,"t hisown"): _swig_setattr(s elf, BallScrew, 'thisown', 0)

_swig_setattr(s elf, BallScrew,self. __class__,BallS crew)

_SHIP.BallScrew _swigregister(B allScrewPtr)

BallScrewCalBac kFunction = _SHIP.BallScrew CalBackFunction
Jul 19 '05 #1
0 2718

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 Python 2.3.1 and GCC 3.2.3 (both installed by default with Slackware) and SWIG 1.3.19, compiled from source code. I messed around a little on my own and couldn't get things to work right, so I copied the examples from the book, nearly verbatim but...
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 wxGetFreeMemory()". Since wxGetFreeMemory() seemed effectively unused in gtk, I just commented it out in misc_wrap.cpp (didn't want to patch SWIG to regenerate the wrapper code, so hacked the generated cpp source), and replaced...
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 Traceback (most recent call last): File "<pyshell#0>", line 1, in -toplevel-
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 environment for Python 2.3.3) and our extensions (C++ code) on Windows with Microsoft Visual C++ 6.0 compiler to generate the extended Python interpreter. It works well on Linux and for the basic Python modules and our special modules on Windows. But...
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 running them using IDLE. To start with the applications worked OK. However, as time has progressed, the error message "ImportError: No module named ****" has been generated with increasing frequency. It has now become impossible to use Python...
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 t2.py as follow: print "this is t2.py" the content of t3.py as follow:
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 cPickle. I've also tried using pickle (instead of cPickle), but I get the same response. Below is the code. I'll put the rest of my comments after the code
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.