SIP

O

omnia neo

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.
 
S

Stefan Behnel

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
 
O

omnia neo

omnia neo, 09.04.2010 07:01:



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

Otherwise, Python can't find it.

Stefan

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

omnia neo

thanks for reply Stefan..
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.
 
G

Gabriel Genellina

omnia neo said:
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)
 
O

omnia neo

omnia neo <neo.omnia7 <at> gmail.com> writes:









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)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top