Some quick googling suggests you may have to call PySys_SetArgv[Ex] (
http://docs.python.org/c-api/init.html#PySys_SetArgvEx ) to set up sys.argv
after calling Py_Initialize(). I haven't actually tried it, though.
-Willem Jan
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
Good to hear. The libraries are just what I needed to add to get it to link
without errors after starting with the -lpython2.6, by the way.
-Willem Jan
#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;
}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...QNetworkRequest request;
request.setUrl(QUrl("http://192.168.224.130:8888/service"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
arrReqBody = "code=print(1+1)"; // This is the sage script which is put in HTTP body request
arrReqBody = request.url().toPercentEncoding(arrReqBody, "=()[].:,");
QNetworkAccessManager *netMgr = new QNetworkAccessManager();
QObject::connect(netMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(sageReply(QNetworkReply*)));
netMgr->post(request, arrReqBody);
"{\"execute_reply\": {\"status\": \"ok\", \"execution_count\": 1, \"user_expressions\": {}, \"payload\": []}, \"success\": true, \"stdout\": \"2\\n\"}"
arrReqBody = "code='Y=Polyhedron(vertices=[(0,0,0,0,0,0,0,0),(0,0,0,1,0,1,0,1),(0,0,0,1,0,1,1,1),(0,0,0,1,1,1,0,1)])";
arrReqBody += "for v in Y.inequality_generator():print v'";
"{\"execute_reply\": {\"status\": \"ok\", \"execution_count\": 1, \"user_expressions\": {}, \"payload\": []}, \"success\": true}"
Thank you, sir, for replying. I tried to run it again after InstallingSage python2, it gives the following error.
Our Sage version is 8.2. We are getting this error.abc@Math-Sans:~/Downloads/SageMath$ sage --python