New user small problem

View: New views
12 Messages — Rating Filter:   Alert me  

New user small problem

by Zer033 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, I am new to using swig and I encountered a problem while trying to get a small example project put together.  

I am trying to figure out how to use C++ function in python using swig, but I can't seem to get it working.  The problem is when I try to compile I get some errors.  

I followed the tutorial for setting up a Microsoft Visual Studio Project here: http://www.dabeaz.com/cgi-bin/wiki.pl?SwigFaqDLLForWindows

I'm using VS 2005.

I pretty much just wanted to duplicate the example from here: http://www.swig.org/tutorial.html

The code in that tutorial is the code I used for the C++ function/header and the example.i that are in my project.

I next downloaded Swig from sourceforge the swigwin.  I unzipped it.

I put the swig.exe in my project folder and tried to compile my project.

I get a bunch of "swig errors" of "Unrecognized option" this and that.  Here is the exact errors:


------ Build started: Project: interfaceDLLexample, Configuration: Debug Win32 ------
SWIG
swig error : Unrecognized option and
swig error : Unrecognized option Settings\Blake
swig error : Unrecognized option Nicholas\Desktop\interfaceDLLexample\\interfaceDLLexample
swig error : Unrecognized option c:\Documents
swig error : Unrecognized option and
swig error : Unrecognized option Settings\Blake
Use 'swig -help' for available options.
Project : error PRJ0019: A tool returned an error code from "SWIG"
Build log was saved at "file://c:\Documents and Settings\Blake Nicholas\Desktop\interfaceDLLexample\interfaceDLLexample\Debug\BuildLog.htm"
interfaceDLLexample - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I am a newbie with swig.  This is probably a pretty easy problem, but I can't really get it and I've tried a few different things.  

Any other suggestions on setting something like this up that differ from the tutorials above would be great.  I don't need to do anything fancy right now I just want to get a simple example module working in python like this example, and if I made any really newbie mistakes please let me know.

The solution can be downloaded here if anyone wants to see the project settings I have.

 
http://www.megaupload.com/?d=SEL82U2Q

Thanks.

Re: New user small problem

by nitro-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am 29.11.2007, 12:15 Uhr, schrieb Zer033 <spband33@...>:

>
> Hi, I am new to using swig and I encountered a problem while trying to  
> get a
> small example project put together.
>
> I am trying to figure out how to use C++ function in python using swig,  
> but
> I can't seem to get it working.  The problem is when I try to compile I  
> get
> some errors.

The errors look like you didn't put all filenames with spaces in quotes.

-Matthias

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: New user small problem

by Christopher Barker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This looks like you're having trouble with running SWIG itself, not yet
with compiling the results. I think another poster has suggested a fix.

However, when you do get to the compiling stage, I highly recommend that
you use distutils and a setup.py file to compile the extension , it is
by far the easiest way to compile python extensions.

I recently added directions to the SWIG docs. I don't know that they've
made it to the released version, but you can find them in svn here:

http://swig.svn.sourceforge.net/viewvc/*checkout*/swig/trunk/Doc/Manual/Python.html

-Chris


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@...

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: New user small problem

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nitro wrote:

> Am 29.11.2007, 12:15 Uhr, schrieb Zer033 <spband33@...>:
>
> > Hi, I am new to using swig and I encountered a problem while trying to  
> > get a
> > small example project put together.
> >
> > I am trying to figure out how to use C++ function in python using
> swig,  
> > but
> > I can't seem to get it working.  The problem is when I try to
> compile I  
> > get
> > some errors.
>
> The errors look like you didn't put all filenames with spaces in quotes.
>

Also, open up the Visual Studio project files in the Examples/python
directory. They work straight off, if you set the env variables as
outlined in http://www.swig.org/Doc1.3/Windows.html#Windows_visual_studio.

William

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: New user small problem

by Zer033 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Christopher Barker wrote:
This looks like you're having trouble with running SWIG itself, not yet
with compiling the results. I think another poster has suggested a fix.

However, when you do get to the compiling stage, I highly recommend that
you use distutils and a setup.py file to compile the extension , it is
by far the easiest way to compile python extensions.

I recently added directions to the SWIG docs. I don't know that they've
made it to the released version, but you can find them in svn here:

http://swig.svn.sourceforge.net/viewvc/*checkout*/swig/trunk/Doc/Manual/Python.html

-Chris


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Chris,
I think that is the problem.  What is it I'm supposed to do with the "swigwin-1.3.33" folder in relation to my VS solution.  I can't find any specific steps concerning that.  I did set the python environmental variables though and that seems to be okay.  

Also to the above poster about the Examples/python things working after setting environmental variables that didn't work for me either.  I think it is related to me just not installing or incorporating swig folder properly with my solution.

Re: New user small problem

by Zer033 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Zer033 wrote:
Christopher Barker wrote:
This looks like you're having trouble with running SWIG itself, not yet
with compiling the results. I think another poster has suggested a fix.

However, when you do get to the compiling stage, I highly recommend that
you use distutils and a setup.py file to compile the extension , it is
by far the easiest way to compile python extensions.

I recently added directions to the SWIG docs. I don't know that they've
made it to the released version, but you can find them in svn here:

http://swig.svn.sourceforge.net/viewvc/*checkout*/swig/trunk/Doc/Manual/Python.html

-Chris


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Chris,
I think that is the problem.  What is it I'm supposed to do with the "swigwin-1.3.33" folder in relation to my VS solution.  I can't find any specific steps concerning that.  I did set the python environmental variables though and that seems to be okay.  

Also to the above poster about the Examples/python things working after setting environmental variables that didn't work for me either.  I think it is related to me just not installing or incorporating swig folder properly with my solution.
Oh forgot to mention here is the new errors so I think it does have something to do with how I am trying to incorporate the swig folder with my VS Solution.

Generating Code...
Compiling manifest to resources...
Linking...
LINK : _example.pyd not found or not built by the last incremental link; performing full link
Embedding manifest...
SWIG
(1): Error: Unable to find 'swig.swg'
(3): Error: Unable to find 'python.swg'
Project : error PRJ0019: A tool returned an error code from "SWIG"
Build log was saved at "file://c:\Documents and Settings\Blake Nicholas\Desktop\interfaceDLLexample\interfaceDLLexample\Debug\BuildLog.htm"
interfaceDLLexample - 1 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Thanks for the help so far.

Re: New user small problem

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Zer033 wrote:

>
>
> Zer033 wrote:
>>
>>
>> Christopher Barker wrote:
>>> This looks like you're having trouble with running SWIG itself, not yet
>>> with compiling the results. I think another poster has suggested a fix.
>>>
>>> However, when you do get to the compiling stage, I highly recommend that
>>> you use distutils and a setup.py file to compile the extension , it is
>>> by far the easiest way to compile python extensions.
>>>
>>> I recently added directions to the SWIG docs. I don't know that they've
>>> made it to the released version, but you can find them in svn here:
>>>
>>> http://swig.svn.sourceforge.net/viewvc/*checkout*/swig/trunk/Doc/Manual/Python.html
>>>
>>> -Chris
>>>
>>>
>>> --
>>> Christopher Barker, Ph.D.
>>> Oceanographer
>>>
>>> Emergency Response Division
>>> NOAA/NOS/OR&R            (206) 526-6959   voice
>>> 7600 Sand Point Way NE   (206) 526-6329   fax
>>> Seattle, WA  98115       (206) 526-6317   main reception
>>>
>>> Chris.Barker@...
>>>
>>> -------------------------------------------------------------------------
>>> SF.Net email is sponsored by: The Future of Linux Business White Paper
>>> from Novell.  From the desktop to the data center, Linux is going
>>> mainstream.  Let it simplify your IT future.
>>> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
>>> _______________________________________________
>>> Swig-user mailing list
>>> Swig-user@...
>>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>>
>>>
>> Chris,
>> I think that is the problem.  What is it I'm supposed to do with the
>> "swigwin-1.3.33" folder in relation to my VS solution.  I can't find any
>> specific steps concerning that.  I did set the python environmental
>> variables though and that seems to be okay.  
>>
>> Also to the above poster about the Examples/python things working after
>> setting environmental variables that didn't work for me either.  I think
>> it is related to me just not installing or incorporating swig folder
>> properly with my solution.
>>
>
> Oh forgot to mention here is the new errors so I think it does have
> something to do with how I am trying to incorporate the swig folder with my
> VS Solution.
>
> Generating Code...
> Compiling manifest to resources...
> Linking...
> LINK : _example.pyd not found or not built by the last incremental link;
> performing full link
> Embedding manifest...
> SWIG
> (1): Error: Unable to find 'swig.swg'
> (3): Error: Unable to find 'python.swg'
> Project : error PRJ0019: A tool returned an error code from "SWIG"
> Build log was saved at "file://c:\Documents and Settings\Blake
> Nicholas\Desktop\interfaceDLLexample\interfaceDLLexample\Debug\BuildLog.htm"
> interfaceDLLexample - 1 error(s), 1 warning(s)

The 2 errors above occur when the SWIG_LIB environment variable is not
set correctly. However, for Windows, if you are using the executable
supplied in swig.exe, you don't need to set this environment variable
unless you have messed around with the location of swig.exe. Basically
if you just unzip swigwin-1.3.33.zip (see comment in the zip file), set
the target language environment variables as described in Windows.html
and then open up the example visual studio solution files, the examples
will just work.

William

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: New user small problem

by Zer033 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


wsfulton wrote:
Zer033 wrote:
>
>
> Zer033 wrote:
>>
>>
>> Christopher Barker wrote:
>>> This looks like you're having trouble with running SWIG itself, not yet
>>> with compiling the results. I think another poster has suggested a fix.
>>>
>>> However, when you do get to the compiling stage, I highly recommend that
>>> you use distutils and a setup.py file to compile the extension , it is
>>> by far the easiest way to compile python extensions.
>>>
>>> I recently added directions to the SWIG docs. I don't know that they've
>>> made it to the released version, but you can find them in svn here:
>>>
>>> http://swig.svn.sourceforge.net/viewvc/*checkout*/swig/trunk/Doc/Manual/Python.html
>>>
>>> -Chris
>>>
>>>
>>> --
>>> Christopher Barker, Ph.D.
>>> Oceanographer
>>>
>>> Emergency Response Division
>>> NOAA/NOS/OR&R            (206) 526-6959   voice
>>> 7600 Sand Point Way NE   (206) 526-6329   fax
>>> Seattle, WA  98115       (206) 526-6317   main reception
>>>
>>> Chris.Barker@noaa.gov
>>>
>>> -------------------------------------------------------------------------
>>> SF.Net email is sponsored by: The Future of Linux Business White Paper
>>> from Novell.  From the desktop to the data center, Linux is going
>>> mainstream.  Let it simplify your IT future.
>>> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
>>> _______________________________________________
>>> Swig-user mailing list
>>> Swig-user@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>>
>>>
>> Chris,
>> I think that is the problem.  What is it I'm supposed to do with the
>> "swigwin-1.3.33" folder in relation to my VS solution.  I can't find any
>> specific steps concerning that.  I did set the python environmental
>> variables though and that seems to be okay.  
>>
>> Also to the above poster about the Examples/python things working after
>> setting environmental variables that didn't work for me either.  I think
>> it is related to me just not installing or incorporating swig folder
>> properly with my solution.
>>
>
> Oh forgot to mention here is the new errors so I think it does have
> something to do with how I am trying to incorporate the swig folder with my
> VS Solution.
>
> Generating Code...
> Compiling manifest to resources...
> Linking...
> LINK : _example.pyd not found or not built by the last incremental link;
> performing full link
> Embedding manifest...
> SWIG
> (1): Error: Unable to find 'swig.swg'
> (3): Error: Unable to find 'python.swg'
> Project : error PRJ0019: A tool returned an error code from "SWIG"
> Build log was saved at "file://c:\Documents and Settings\Blake
> Nicholas\Desktop\interfaceDLLexample\interfaceDLLexample\Debug\BuildLog.htm"
> interfaceDLLexample - 1 error(s), 1 warning(s)

The 2 errors above occur when the SWIG_LIB environment variable is not
set correctly. However, for Windows, if you are using the executable
supplied in swig.exe, you don't need to set this environment variable
unless you have messed around with the location of swig.exe. Basically
if you just unzip swigwin-1.3.33.zip (see comment in the zip file), set
the target language environment variables as described in Windows.html
and then open up the example visual studio solution files, the examples
will just work.

William

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
What is the environmental variable I have to set exactly and then what option in my VS solution do I put it under.  Is it just an environmental variable for the swig root folder?  Then after that in the VS solution settings where is it that I include it.

Re: New user small problem

by Christopher Barker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Zer033 wrote:
> Chris,
> I think that is the problem.  What is it I'm supposed to do with the
> "swigwin-1.3.33" folder in relation to my VS solution.

What I was suggesting does not involve the VS GUI at all -- strictly
command line:

swig --python MyFile.i

python setup.py build_ext

If you're still working on your C/C++ code in VS, then I suppose it
makes sense to figure out out to use the Provided solution. But you
might want to see if it works on the command-line as a way to test, anyway.

-Chris







--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@...

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: New user small problem

by Zer033 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Zer033 wrote:
wsfulton wrote:
Zer033 wrote:
>
>
> Zer033 wrote:
>>
>>
>> Christopher Barker wrote:
>>> This looks like you're having trouble with running SWIG itself, not yet
>>> with compiling the results. I think another poster has suggested a fix.
>>>
>>> However, when you do get to the compiling stage, I highly recommend that
>>> you use distutils and a setup.py file to compile the extension , it is
>>> by far the easiest way to compile python extensions.
>>>
>>> I recently added directions to the SWIG docs. I don't know that they've
>>> made it to the released version, but you can find them in svn here:
>>>
>>> http://swig.svn.sourceforge.net/viewvc/*checkout*/swig/trunk/Doc/Manual/Python.html
>>>
>>> -Chris
>>>
>>>
>>> --
>>> Christopher Barker, Ph.D.
>>> Oceanographer
>>>
>>> Emergency Response Division
>>> NOAA/NOS/OR&R            (206) 526-6959   voice
>>> 7600 Sand Point Way NE   (206) 526-6329   fax
>>> Seattle, WA  98115       (206) 526-6317   main reception
>>>
>>> Chris.Barker@noaa.gov
>>>
>>> -------------------------------------------------------------------------
>>> SF.Net email is sponsored by: The Future of Linux Business White Paper
>>> from Novell.  From the desktop to the data center, Linux is going
>>> mainstream.  Let it simplify your IT future.
>>> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
>>> _______________________________________________
>>> Swig-user mailing list
>>> Swig-user@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>>
>>>
>> Chris,
>> I think that is the problem.  What is it I'm supposed to do with the
>> "swigwin-1.3.33" folder in relation to my VS solution.  I can't find any
>> specific steps concerning that.  I did set the python environmental
>> variables though and that seems to be okay.  
>>
>> Also to the above poster about the Examples/python things working after
>> setting environmental variables that didn't work for me either.  I think
>> it is related to me just not installing or incorporating swig folder
>> properly with my solution.
>>
>
> Oh forgot to mention here is the new errors so I think it does have
> something to do with how I am trying to incorporate the swig folder with my
> VS Solution.
>
> Generating Code...
> Compiling manifest to resources...
> Linking...
> LINK : _example.pyd not found or not built by the last incremental link;
> performing full link
> Embedding manifest...
> SWIG
> (1): Error: Unable to find 'swig.swg'
> (3): Error: Unable to find 'python.swg'
> Project : error PRJ0019: A tool returned an error code from "SWIG"
> Build log was saved at "file://c:\Documents and Settings\Blake
> Nicholas\Desktop\interfaceDLLexample\interfaceDLLexample\Debug\BuildLog.htm"
> interfaceDLLexample - 1 error(s), 1 warning(s)

The 2 errors above occur when the SWIG_LIB environment variable is not
set correctly. However, for Windows, if you are using the executable
supplied in swig.exe, you don't need to set this environment variable
unless you have messed around with the location of swig.exe. Basically
if you just unzip swigwin-1.3.33.zip (see comment in the zip file), set
the target language environment variables as described in Windows.html
and then open up the example visual studio solution files, the examples
will just work.

William

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
What is the environmental variable I have to set exactly and then what option in my VS solution do I put it under.  Is it just an environmental variable for the swig root folder?  Then after that in the VS solution settings where is it that I include it.
I got it all to compile and the new files added to the VS solution folder were:

example.py, _example.exp, _example.lib, and _example.pyd.

I open up python and try it out and it doesn't work like the tutorial.

The tutorial says type:

import example

which gives no errors

so I type

example.fact(5)

when I do this I get this error

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    example.fact(5)
AttributeError: 'module' object has no attribute 'fact'

so at first I didn't think it was working at all, but this works

example.example.fact(5)

It works as far as existing unlike the one above, but doesn't give the answer back. I guess this is because I made example a class with header/cpp files.  So I know how I could rearrange the code and get example.fact(5) working.  

The thing I'm interested in is when I type

example.example.fact(5)

I get this error

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    example.example.fact(5)
TypeError: unbound method fact() must be called with example instance as first argument (got int instance instead)

Just for curiosity and the possibility I might encounter it in a more complex project later what does this mean?

Also thanks for all your help so far I do understand how to use swig and python now and could do it with other projects.

Re: New user small problem

by Zer033 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Zer033 wrote:
Zer033 wrote:
wsfulton wrote:
Zer033 wrote:
>
>
> Zer033 wrote:
>>
>>
>> Christopher Barker wrote:
>>> This looks like you're having trouble with running SWIG itself, not yet
>>> with compiling the results. I think another poster has suggested a fix.
>>>
>>> However, when you do get to the compiling stage, I highly recommend that
>>> you use distutils and a setup.py file to compile the extension , it is
>>> by far the easiest way to compile python extensions.
>>>
>>> I recently added directions to the SWIG docs. I don't know that they've
>>> made it to the released version, but you can find them in svn here:
>>>
>>> http://swig.svn.sourceforge.net/viewvc/*checkout*/swig/trunk/Doc/Manual/Python.html
>>>
>>> -Chris
>>>
>>>
>>> --
>>> Christopher Barker, Ph.D.
>>> Oceanographer
>>>
>>> Emergency Response Division
>>> NOAA/NOS/OR&R            (206) 526-6959   voice
>>> 7600 Sand Point Way NE   (206) 526-6329   fax
>>> Seattle, WA  98115       (206) 526-6317   main reception
>>>
>>> Chris.Barker@noaa.gov
>>>
>>> -------------------------------------------------------------------------
>>> SF.Net email is sponsored by: The Future of Linux Business White Paper
>>> from Novell.  From the desktop to the data center, Linux is going
>>> mainstream.  Let it simplify your IT future.
>>> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
>>> _______________________________________________
>>> Swig-user mailing list
>>> Swig-user@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>>
>>>
>> Chris,
>> I think that is the problem.  What is it I'm supposed to do with the
>> "swigwin-1.3.33" folder in relation to my VS solution.  I can't find any
>> specific steps concerning that.  I did set the python environmental
>> variables though and that seems to be okay.  
>>
>> Also to the above poster about the Examples/python things working after
>> setting environmental variables that didn't work for me either.  I think
>> it is related to me just not installing or incorporating swig folder
>> properly with my solution.
>>
>
> Oh forgot to mention here is the new errors so I think it does have
> something to do with how I am trying to incorporate the swig folder with my
> VS Solution.
>
> Generating Code...
> Compiling manifest to resources...
> Linking...
> LINK : _example.pyd not found or not built by the last incremental link;
> performing full link
> Embedding manifest...
> SWIG
> (1): Error: Unable to find 'swig.swg'
> (3): Error: Unable to find 'python.swg'
> Project : error PRJ0019: A tool returned an error code from "SWIG"
> Build log was saved at "file://c:\Documents and Settings\Blake
> Nicholas\Desktop\interfaceDLLexample\interfaceDLLexample\Debug\BuildLog.htm"
> interfaceDLLexample - 1 error(s), 1 warning(s)

The 2 errors above occur when the SWIG_LIB environment variable is not
set correctly. However, for Windows, if you are using the executable
supplied in swig.exe, you don't need to set this environment variable
unless you have messed around with the location of swig.exe. Basically
if you just unzip swigwin-1.3.33.zip (see comment in the zip file), set
the target language environment variables as described in Windows.html
and then open up the example visual studio solution files, the examples
will just work.

William

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
What is the environmental variable I have to set exactly and then what option in my VS solution do I put it under.  Is it just an environmental variable for the swig root folder?  Then after that in the VS solution settings where is it that I include it.
I got it all to compile and the new files added to the VS solution folder were:

example.py, _example.exp, _example.lib, and _example.pyd.

I open up python and try it out and it doesn't work like the tutorial.

The tutorial says type:

import example

which gives no errors

so I type

example.fact(5)

when I do this I get this error

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    example.fact(5)
AttributeError: 'module' object has no attribute 'fact'

so at first I didn't think it was working at all, but this works

example.example.fact(5)

It works as far as existing unlike the one above, but doesn't give the answer back. I guess this is because I made example a class with header/cpp files.  So I know how I could rearrange the code and get example.fact(5) working.  

The thing I'm interested in is when I type

example.example.fact(5)

I get this error

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    example.example.fact(5)
TypeError: unbound method fact() must be called with example instance as first argument (got int instance instead)

Just for curiosity and the possibility I might encounter it in a more complex project later what does this mean?

Also thanks for all your help so far I do understand how to use swig and python now and could do it with other projects.
I figured the above problem out it was just a small code error.

Thanks again for all the help really appreciated!

Re: New user small problem

by nitro-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> The thing I'm interested in is when I type
>
> example.example.fact(5)
>
> I get this error
>
> Traceback (most recent call last):
>   File "<pyshell#4>", line 1, in <module>
>     example.example.fact(5)
> TypeError: unbound method fact() must be called with example instance as
> first argument (got int instance instead)
>
> Just for curiosity and the possibility I might encounter it in a more
> complex project later what does this mean?

Sounds like you are doing something like this:

class MyClass(object):
     def test(self, x):
         print x

     @staticmethod
     def test2(x):
         print x

klass = MyClass
klass_instance = MyClass()
klass.test(5)                    # error!
klass_instance.test(5)           # good! it's the same as  
klass.test( klass_instance, 5 )

In this example there is a class object and there is a class instance  
object. You can only call fact as-is on the instance object. If you try to  
call it on a plain class object you get the error above, because python  
expects the first argument of test (= "self") to be a class instance. If  
you want to use "test" like a static method (it doesn't depend on any  
instance-specific data) you can do it like shown above with "test2".
I guess you should read some python tutorials on classes to understand  
what I am trying to tell here. I am sure other people are more talented at  
explaining this than I am.

-Matthias

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user