473,287 Members | 1,565 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,287 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)

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 2668

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

Similar topics

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
2
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
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
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
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
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
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
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
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
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"....
0
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...
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: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...

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.