On Tue, Jan 30, 2018 at 2:35 PM, J. Javan <jafarjava...@gmail.com> wrote:
> I can see that you have successfully linked against sage.
> I also have a Qt GUI application which needs to do some mathematics in the
> background.
> This application is targeted for windows platforms. I have installed sage
> from this link.
> Could you please guide me on how to link my app with sage?
>
> I'm running your code as below
>
> #include <Python.h>
>
>
> int main(int argc, char *argv[])
>
> {
>
>
>     int retVal = 0;
>
>     Py_Initialize();
>
>     PySys_SetArgv(argc, (wchar_t**) argv);
>
>     printf("1+1:\n");
>
>     PyRun_SimpleString("print (1+1)");
>
>     printf("Load sage \n");
>
>     retVal = PyRun_SimpleString("from sage.all import *");
>
>     printf("Factor 2310:\n");
>
>     PyRun_SimpleString("print factor(2310)");
>
>     Py_Finalize();
>
>     return 0;
>
> }
>
>
> And this gives me the following output:
>
> 1+1:
> 2
> Load sage
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
> ModuleNotFoundError: No module named 'sage'
> Factor 2310:
>   File "<string>", line 1
>     print factor(2310)
>                ^
> SyntaxError: invalid syntax
> Press <RETURN> to close this window...
>
> The output is clearly stating that sage cannot be found.
> This is because I have linked to my locally compiled python static
> libraries(Actually I have downloaded python source code and linked against
> it.) which are not aware of sage.
>
> Also I tried to link against python provided in sage installation but I
> can't find any "python.lib" in it.
> I have also set an environment variable $SAGE_LOCAL pointing to "C:\Program
> Files\SageMath 8.1\runtime\opt\sagemath-8.1\local" but no luck.
>
> Environment:
> Qt_v5.9
> Windows 7
> Python_v3.6.4
> Sage_v8.1

Hi,

I saw this mail forwarded to sage-devel, but it appears to be missing
quite a lot of context.  What, specifically, is it that you're trying
to do?

To be clear, Sage for Windows is not just a Python module.  It's an
entire software suite, including its own Python interpreter.  All of
it is complied with Cygwin.  You won't be able to "import sage" from
different Python.

If you're trying to build an application that uses Sage internally
somehow you have two choices really--build the entire software inside
Sage's environment (you can do this, for example, from the Sage Shell
which is really a Cygwin shell in the Sage environment).  That is,
build all your software in Cygwin, linking with the Python in Sage,
etc.  This can be tricky unless you know what you're doing with Sage's
development environment.

Your other alternative is that you can always call Sage's Python from
outside Sage (but again, you'll still have to set a few environment
variables at a minimum), and depending on how Python is integrated
into your software this could mean anything from running the Python
interpreter as a subprocess and communicating with it, to dynamically
linking with the libpython DLL in Sage and running C Python code like
in your example above.  Though to be honest I'm not exactly sure if
it's possible to link a Cygwin DLL into a non-Cygwin executable. But I
think maybe it's possible....

Please let me know more about what you're trying to do though and I
can probably be of more help.

Best,
E


> On Wednesday, September 14, 2011 at 4:15:58 AM UTC+4:30, Michael Rubinstein
> wrote:
>>
>> Thanks! That worked for me too, though I'm not sure how you decided on
>> the specific
>> choices of libraries to link to.
>>
>> Mike
>>
>> On Sep 13, 6:39 pm, Willem Jan Palenstijn <w...@usecode.org> wrote:
>> > On Tue, Sep 13, 2011 at 08:46:05AM -0700, Michael Rubinstein wrote:
>> >
>> > > I tried adding PySys_SetArgv(argc, argv); after Py_Initialize();
>> > > It gets me further but then gives a strange error message:
>> >
>> > > Loading the Sage library...
>> >
>> > > ------------------------------------------------------------
>> > > Unhandled SIGSEGV: A segmentation fault occurred in Sage.
>> > > This probably occurred because a *compiled* component
>> > > of Sage has a bug in it (typically accessing invalid memory)
>> > > or is not properly wrapped with _sig_on, _sig_off.
>> > > You might want to run Sage under gdb with 'sage -gdb' to debug this.
>> > > Sage will now terminate (sorry).
>> > > ------------------------------------------------------------
>> >
>> > I've just tried it here with your embed.c + PySys_SetArgv(argc, argv),
>> > and it
>> > works for me when I link against libpython2.6 dynamically:
>> >
>> > $ gcc -I$SAGE_LOCAL/include/python2.6 embed.c -lpython2.6  -lm -lutil
>> > -lpthread -ldl -o embed
>> > $ ./embed
>> > 1+1:
>> > 2
>> > Load sage
>> > Factor 2310:
>> > 2 * 3 * 5 * 7 * 11
>> > $
>> >
>> > This is 64 bit linux with sage 4.7.1rc1.
>> >
>> > -Willem Jan
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to