Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SIP

3 views
Skip to first unread message

omnia neo

unread,
Apr 9, 2010, 1:01:51 AM4/9/10
to
Hi All,

I was looking at the SIP tool to create a C extensions for python to
call.
Here is what I tried:
1. I created a simple c file and .h file <attached testfunc.c and
testfunc.h>
2. Then I created a corresponding testfunc.sip file
###################
%CModule siptest 0

%UnitCode
#include"testfunc.h"
%End

void pyfunc();
%MethodCode
func1();
%End
####################

3. I ran SIP <command: sip -e -j 1 -c . testfunc.sip> on this which
generated the following files:
sipsiptestpart0.c and sipAPIsiptest.h
4. I then added these generated files along with testfunc.c and
testfunc.h in my MS Visual studios solution to create a testsip.dll
file
5. Now to call my module from this dll I invoke a script which tries
to import my modules. My pythn call is as follows:

#code#
import siptest

I get following error :
import error : no module named siptest

Please help me find what I am not doing or what mistake am i commiting.

Stefan Behnel

unread,
Apr 9, 2010, 1:30:23 AM4/9/10
to pytho...@python.org
omnia neo, 09.04.2010 07:01:

> import siptest
>
> I get following error :
> import error : no module named siptest

Is the directory where your siptest.dll lies in your PYTHONPATH (sys.path)?

Otherwise, Python can't find it.

Stefan

omnia neo

unread,
Apr 9, 2010, 1:42:19 AM4/9/10
to

thanks for reply Stefan..
well I added PYTHONPATH = <my dll path> in my environment variables
(windows XP).

omnia neo

unread,
Apr 9, 2010, 1:51:39 AM4/9/10
to

well I just tried this too.
I added the path using sys.path on the fly in my python script as
follows:

###############
import sys
sys.path.append("<dll path>")
print sys.path
import siptest
###############

again same error:
ImportError: No module named siptest.

Gabriel Genellina

unread,
Apr 9, 2010, 10:41:31 AM4/9/10
to pytho...@python.org
omnia neo <neo.omnia7 <at> gmail.com> writes:
> On Apr 9, 10:42 am, omnia neo <neo.omn...@gmail.com> wrote:
> > On Apr 9, 10:30 am, Stefan Behnel <stefan...@behnel.de> wrote:
> >
> > > omnia neo, 09.04.2010 07:01:
> >
> > > > import siptest
> >
> > > > I get following error :
> > > > import error : no module named siptest
> >
> > > Is the directory where your siptest.dll lies in your PYTHONPATH
(sys.path)?
> > well I added PYTHONPATH = <my dll path> in my environment variables
> > (windows XP).
>
> well I just tried this too.
> I added the path using sys.path on the fly in my python script as
> follows:
>
> ###############
> import sys
> sys.path.append("<dll path>")
> print sys.path
> import siptest
> ###############
>
> again same error:
> ImportError: No module named siptest.

Make sure the extension module must is called siptest.pyd, not siptest.dll
http://docs.python.org/extending/windows.html
(I'd expect SIP to take care of this)

--
Gabriel Genellina

omnia neo

unread,
Apr 13, 2010, 12:17:14 AM4/13/10
to
On Apr 9, 7:41 pm, Gabriel Genellina <gagsl-...@yahoo.com.ar> wrote:
> omnia neo <neo.omnia7 <at> gmail.com> writes:
>
>
>
>
>
> > On Apr 9, 10:42 am, omnia neo <neo.omn...@gmail.com> wrote:
> > > On Apr 9, 10:30 am, Stefan Behnel <stefan...@behnel.de> wrote:
>
> > > > omnia neo, 09.04.2010 07:01:
>
> > > > > import siptest
>
> > > > > I get following error :
> > > > > import error : no module named siptest
>
> > > > Is the directory where your siptest.dll lies in your PYTHONPATH
> (sys.path)?
> > > well I added PYTHONPATH = <my dll path> in my environment variables
> > > (windows XP).
>
> > well I just tried this too.
> > I added the path using sys.path on the fly in my python script as
> > follows:
>
> > ###############
> > import sys
> > sys.path.append("<dll path>")
> > print sys.path
> > import siptest
> > ###############
>
> > again same error:
> > ImportError: No module named siptest.
>
> Make sure the extension module must is called siptest.pyd, not siptest.dllhttp://docs.python.org/extending/windows.html

> (I'd expect SIP to take care of this)
>
> --
> Gabriel Genellina- Hide quoted text -
>
> - Show quoted text -

SIP tool installation steps are as follows:
• Download latest SIP from: http://www.riverbankcomputing.co.uk/software/sip/download
and unzip to any location.
• Make sure python is in PATH of environment variables -> PATH = %PATH
%;C:\python26
• Go to cmd promt -> go to the SIP location (location of download) ->
run :/python configure.py
• It will take all the default setting for configuration, the default
directories will be in c:\python26 (change if required)
• Go to Start -> programs -> MS visual studios -> visuals studio tools-
> command prompt. Go to SIP folder (location of download)
• \> nmake -> this will run makefile and build sip.exe and sip.pyd
• \> nmake install -> this will copy: sip.exe, sip.pyd,sip.h,
sipconfig.py, sipdistutils.py in C:\python26 <default locations>
• Go to the folder where the manually written .sip file is present in
command prompt and run the following:
sip -e -j 1 -c . xyz.sip

Steps to create an extension module:
1. Create a “.sip” specification file for the C/C++ library
a. Follow the syntax definitions as given in
http://www.riverbankcomputing.co.uk/static/Docs/sip4/specification_files.html#syntax-definition
b. Appropriately add the C/C++ classes, functions, methods and
structures in the specification file.
2. Run the SIP tool utility on the specification file to create the
intermediate C/C++ code.
3. Copy and edit the simple build script as shown in
http://www.riverbankcomputing.co.uk/static/Docs/sip4/using.html#a-simple-c-example
4. Run the build script to create the makefile, the CModule, the .sbf
files
5. Run Visual Studios nmake utility on the makefile to create the .pyd
file which is the final module which can be imported from python.


0 new messages