[C++-sig] C++-sig Digest, Vol 51, Issue 26

Shrikant Chikhalkar shrikantvc at gmail.com
Fri Oct 26 12:27:00 CEST 2007


I got solution for the problem.

using root credentials run following command on shell prompt
$python2 setup.py install

where setup.py would be
from distutils.core import setup
setup(name='xxx',
      version='1.0',
      py_modules=['py_function'],
      )

thanks
shrikant

On 10/25/07, c++-sig-request at python.org <c++-sig-request at python.org> wrote:
>
> Send C++-sig mailing list submissions to
>         c++-sig at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mail.python.org/mailman/listinfo/c++-sig
> or, via email, send a message with subject or body 'help' to
>         c++-sig-request at python.org
>
> You can reach the person managing the list at
>         c++-sig-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of C++-sig digest..."
>
>
> Today's Topics:
>
>    1. Re: C++-sig Digest, Vol 51, Issue 25 (Shrikant Chikhalkar)
>    2. Re: C++-sig Digest, Vol 51, Issue 25 (Shrikant Chikhalkar)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 25 Oct 2007 16:33:42 +0530
> From: "Shrikant Chikhalkar" <shrikantvc at gmail.com>
> Subject: Re: [C++-sig] C++-sig Digest, Vol 51, Issue 25
> To: c++-sig at python.org
> Message-ID:
>         <87de5f460710250403q311e8fd1q61de04dc7b935f88 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
> thanks for the reply.
> that i have already tried. Still i am getting same error. could you please
> give some pointer that where i am doing wrong.
>
> thanks
> Shrikant
>
>
> On 10/25/07, c++-sig-request at python.org <c++-sig-request at python.org>
> wrote:
> >
> > Send C++-sig mailing list submissions to
> >         c++-sig at python.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >         http://mail.python.org/mailman/listinfo/c++-sig
> > or, via email, send a message with subject or body 'help' to
> >         c++-sig-request at python.org
> >
> > You can reach the person managing the list at
> >         c++-sig-owner at python.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of C++-sig digest..."
> >
> >
> > Today's Topics:
> >
> >    1. failed in PyImport_Import() (Shrikant Chikhalkar)
> >    2. Re: failed in PyImport_Import() (Gustavo Carneiro)
> >
> >
> > ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Thu, 25 Oct 2007 12:22:24 +0530
> > From: "Shrikant Chikhalkar" <shrikantvc at gmail.com>
> > Subject: [C++-sig] failed in PyImport_Import()
> > To: c++-sig at python.org
> > Message-ID:
> >         <87de5f460710242352w5b57dc4djbcfba96ccf0f3578 at mail.gmail.com>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> > Hi,
> >
> > i am tring to call python function from 'C' program. i get NULL value
> > return
> > by PyImport_Import()
> >
> > following is the code. code is copied from
> > http://www.codeproject.com/cpp/embedpython_1.asp
> >
> > following file is saved as
> >
> > call_function.c
> >
> >
> >
> /************************************************************************************************************/
> >
> > // call_function.c - A sample of calling
> > // python functions from C code
> > //
> > #include <Python.h>
> >
> > int main(int argc, char *argv[])
> > {
> >     PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
> >
> >     if (argc < 3)
> >     {
> >         printf("Usage: exe_name python_source function_name\n");
> >         return 1;
> >     }
> >
> >     // Initialize the Python Interpreter
> >     Py_Initialize();
> >
> >     // Build the name object
> >     pName = PyString_FromString(argv[1]);
> >
> >     // Load the module object
> >     pModule = PyImport_Import(pName);
> >
> >     // pDict is a borrowed reference
> >     pDict = PyModule_GetDict(pModule);
> >
> >     // pFunc is also a borrowed reference
> >     pFunc = PyDict_GetItemString(pDict, argv[2]);
> >
> >     if (PyCallable_Check(pFunc))
> >     {
> >         PyObject_CallObject(pFunc, NULL);
> >     } else
> >     {
> >         PyErr_Print();
> >     }
> >
> >     // Clean up
> >     Py_DECREF(pModule);
> >     Py_DECREF(pName);
> >
> >     // Finish the Python Interpreter
> >     Py_Finalize();
> >
> >     return 0;
> > }
> >
> >
> >
> /************************************************************************************************************/
> > python file saved as
> >
> > py_function.py
> >
> >
> >
> /************************************************************************************************************/
> >
> > '''py_function.py - Python source designed to '''
> > '''demonstrate the use of python embedding'''
> >
> > def multiply():
> >     c = 12345*6789
> >     print 'The result of 12345 x 6789 :', c
> >
> >
> >     return c
> >
> >
> >
> /************************************************************************************************************/
> >
> > $gcc -g call_function.c  -lpython2.5 -ocall_function
> > $./call_function py_function.py multiply
> >
> > i get following output
> >
> > ImportError: No module named py_function
> > Failed to load "py_function"
> >
> > when i kdbg(debug) it i vet NULL value returned from PyImport_Import()..
> >
> > can any one please find out the error that i am doing.
> >
> > --
> > Shrikant
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL:
> >
> http://mail.python.org/pipermail/c++-sig/attachments/20071025/e3ca2dfd/attachment-0001.htm
> >
> > ------------------------------
> >
> > Message: 2
> > Date: Thu, 25 Oct 2007 08:21:19 +0100
> > From: "Gustavo Carneiro" <gjcarneiro at gmail.com>
> > Subject: Re: [C++-sig] failed in PyImport_Import()
> > To: "Development of Python/C++ integration" <c++-sig at python.org>
> > Message-ID:
> >         <a467ca4f0710250021x50e0a9c8m5ad849e9b9e3d5b1 at mail.gmail.com>
> > Content-Type: text/plain; charset="utf-8"
> >
> > On 25/10/2007, Shrikant Chikhalkar <shrikantvc at gmail.com> wrote:
> > >
> > > Hi,
> > >
> > > i am tring to call python function from 'C' program. i get NULL value
> > > return by PyImport_Import()
> > >
> > > following is the code. code is copied from
> > > http://www.codeproject.com/cpp/embedpython_1.asp
> > >
> > > following file is saved as
> > >
> > > call_function.c
> > >
> > >
> >
> /************************************************************************************************************/
> > >
> > >
> > > // call_function.c - A sample of calling
> > > // python functions from C code
> > >
> > > //
> > > #include <Python.h>
> > >
> > > int main(int argc, char *argv[])
> > > {
> > >
> > >     PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
> > >
> > >     if (argc < 3)
> > >     {
> > >         printf("Usage: exe_name python_source function_name\n"
> > > );
> > >         return 1;
> > >     }
> > >
> > >     // Initialize the Python Interpreter
> > >     Py_Initialize();
> > >
> > >
> > > // Build the name object
> > >     pName = PyString_FromString(argv[1]);
> > >
> > >     // Load the module object
> > >     pModule = PyImport_Import(pName);
> > >
> > >
> > >     // pDict is a borrowed reference
> > >     pDict = PyModule_GetDict(pModule);
> > >
> > >     // pFunc is also a borrowed reference
> > >     pFunc = PyDict_GetItemString(pDict, argv[
> > > 2]);
> > >
> > >     if (PyCallable_Check(pFunc))
> > >     {
> > >         PyObject_CallObject(pFunc, NULL);
> > >     } else
> > >     {
> > >
> > >         PyErr_Print();
> > >     }
> > >
> > >     // Clean up
> > >     Py_DECREF(pModule);
> > >     Py_DECREF(pName);
> > >
> > >     // Finish the Python Interpreter
> > >
> > >     Py_Finalize();
> > >
> > >     return 0;
> > > }
> > >
> > >
> >
> /************************************************************************************************************/
> > >
> > > python file saved as
> > >
> > > py_function.py
> > >
> > >
> > >
> >
> /************************************************************************************************************/
> > >
> > > '''py_function.py - Python source designed to '''
> > > '''demonstrate the use of python embedding'''
> > >
> > > def multiply():
> > >     c = 12345*6789
> > >     print 'The result of 12345 x 6789 :', c
> > >
> > >
> > >
> > >     return c
> > >
> > >
> > >
> >
> /************************************************************************************************************/
> > >
> > > $gcc -g call_function.c  -lpython2.5 -ocall_function
> > > $./call_function py_function.py multiply
> >
> >
> > Shouldn't this be:
> >    $./call_function py_function multiply
> >
> > I.e., you the module name should not have a .py extension.
> >
> > i get following output
> > >
> > > ImportError: No module named py_function
> > > Failed to load "py_function"
> > >
> > > when i kdbg(debug) it i vet NULL value returned from
> PyImport_Import()..
> > >
> > > can any one please find out the error that i am doing.
> > >
> > > --
> > > Shrikant
> > >
> > >
> > > _______________________________________________
> > > C++-sig mailing list
> > > C++-sig at python.org
> > > http://mail.python.org/mailman/listinfo/c++-sig
> > >
> > >
> >
> >
> > --
> > Gustavo J. A. M. Carneiro
> > INESC Porto, Telecommunications and Multimedia Unit
> > "The universe is always one step beyond logic." -- Frank Herbert
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL:
> >
> http://mail.python.org/pipermail/c++-sig/attachments/20071025/0fc3b1ea/attachment-0001.htm
> >
> > ------------------------------
> >
> > _______________________________________________
> > C++-sig mailing list
> > C++-sig at python.org
> > http://mail.python.org/mailman/listinfo/c++-sig
> >
> >
> > End of C++-sig Digest, Vol 51, Issue 25
> > ***************************************
> >
>
>
>
> --
> Shrikant Chikhalkar
> +91 9850991554
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.python.org/pipermail/c++-sig/attachments/20071025/63f1ada0/attachment-0001.htm
>
> ------------------------------
>
> Message: 2
> Date: Thu, 25 Oct 2007 16:54:02 +0530
> From: "Shrikant Chikhalkar" <shrikantvc at gmail.com>
> Subject: Re: [C++-sig] C++-sig Digest, Vol 51, Issue 25
> To: c++-sig at python.org
> Message-ID:
>         <87de5f460710250424k1ef321aei273ae019035bf476 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> I have also check that "py_function.py" is in the same directory.
> i have some doubt
> 1) do we need to install "py_function" module before calling multiply
> function from that. ( install means python -m  py_function)
> 2) individually multiply function is working fine on python prompt.
> 3) I am using python2.5 headers
>
> I know some where i had make a mistake. please help me to locate that
>
> thanks
> Shrikant
>
> On 10/25/07, c++-sig-request at python.org <c++-sig-request at python.org>
> wrote:
> >
> > Send C++-sig mailing list submissions to
> >         c++-sig at python.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >         http://mail.python.org/mailman/listinfo/c++-sig
> > or, via email, send a message with subject or body 'help' to
> >         c++-sig-request at python.org
> >
> > You can reach the person managing the list at
> >         c++-sig-owner at python.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of C++-sig digest..."
> >
> >
> > Today's Topics:
> >
> >    1. failed in PyImport_Import() (Shrikant Chikhalkar)
> >    2. Re: failed in PyImport_Import() (Gustavo Carneiro)
> >
> >
> > ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Thu, 25 Oct 2007 12:22:24 +0530
> > From: "Shrikant Chikhalkar" <shrikantvc at gmail.com>
> > Subject: [C++-sig] failed in PyImport_Import()
> > To: c++-sig at python.org
> > Message-ID:
> >         <87de5f460710242352w5b57dc4djbcfba96ccf0f3578 at mail.gmail.com>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> > Hi,
> >
> > i am tring to call python function from 'C' program. i get NULL value
> > return
> > by PyImport_Import()
> >
> > following is the code. code is copied from
> > http://www.codeproject.com/cpp/embedpython_1.asp
> >
> > following file is saved as
> >
> > call_function.c
> >
> >
> >
> /************************************************************************************************************/
> >
> > // call_function.c - A sample of calling
> > // python functions from C code
> > //
> > #include <Python.h>
> >
> > int main(int argc, char *argv[])
> > {
> >     PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
> >
> >     if (argc < 3)
> >     {
> >         printf("Usage: exe_name python_source function_name\n");
> >         return 1;
> >     }
> >
> >     // Initialize the Python Interpreter
> >     Py_Initialize();
> >
> >     // Build the name object
> >     pName = PyString_FromString(argv[1]);
> >
> >     // Load the module object
> >     pModule = PyImport_Import(pName);
> >
> >     // pDict is a borrowed reference
> >     pDict = PyModule_GetDict(pModule);
> >
> >     // pFunc is also a borrowed reference
> >     pFunc = PyDict_GetItemString(pDict, argv[2]);
> >
> >     if (PyCallable_Check(pFunc))
> >     {
> >         PyObject_CallObject(pFunc, NULL);
> >     } else
> >     {
> >         PyErr_Print();
> >     }
> >
> >     // Clean up
> >     Py_DECREF(pModule);
> >     Py_DECREF(pName);
> >
> >     // Finish the Python Interpreter
> >     Py_Finalize();
> >
> >     return 0;
> > }
> >
> >
> >
> /************************************************************************************************************/
> > python file saved as
> >
> > py_function.py
> >
> >
> >
> /************************************************************************************************************/
> >
> > '''py_function.py - Python source designed to '''
> > '''demonstrate the use of python embedding'''
> >
> > def multiply():
> >     c = 12345*6789
> >     print 'The result of 12345 x 6789 :', c
> >
> >
> >     return c
> >
> >
> >
> /************************************************************************************************************/
> >
> > $gcc -g call_function.c  -lpython2.5 -ocall_function
> > $./call_function py_function.py multiply
> >
> > i get following output
> >
> > ImportError: No module named py_function
> > Failed to load "py_function"
> >
> > when i kdbg(debug) it i vet NULL value returned from PyImport_Import()..
> >
> > can any one please find out the error that i am doing.
> >
> > --
> > Shrikant
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL:
> >
> http://mail.python.org/pipermail/c++-sig/attachments/20071025/e3ca2dfd/attachment-0001.htm
> >
> > ------------------------------
> >
> > Message: 2
> > Date: Thu, 25 Oct 2007 08:21:19 +0100
> > From: "Gustavo Carneiro" <gjcarneiro at gmail.com>
> > Subject: Re: [C++-sig] failed in PyImport_Import()
> > To: "Development of Python/C++ integration" <c++-sig at python.org>
> > Message-ID:
> >         <a467ca4f0710250021x50e0a9c8m5ad849e9b9e3d5b1 at mail.gmail.com>
> > Content-Type: text/plain; charset="utf-8"
> >
> > On 25/10/2007, Shrikant Chikhalkar <shrikantvc at gmail.com> wrote:
> > >
> > > Hi,
> > >
> > > i am tring to call python function from 'C' program. i get NULL value
> > > return by PyImport_Import()
> > >
> > > following is the code. code is copied from
> > > http://www.codeproject.com/cpp/embedpython_1.asp
> > >
> > > following file is saved as
> > >
> > > call_function.c
> > >
> > >
> >
> /************************************************************************************************************/
> > >
> > >
> > > // call_function.c - A sample of calling
> > > // python functions from C code
> > >
> > > //
> > > #include <Python.h>
> > >
> > > int main(int argc, char *argv[])
> > > {
> > >
> > >     PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
> > >
> > >     if (argc < 3)
> > >     {
> > >         printf("Usage: exe_name python_source function_name\n"
> > > );
> > >         return 1;
> > >     }
> > >
> > >     // Initialize the Python Interpreter
> > >     Py_Initialize();
> > >
> > >
> > > // Build the name object
> > >     pName = PyString_FromString(argv[1]);
> > >
> > >     // Load the module object
> > >     pModule = PyImport_Import(pName);
> > >
> > >
> > >     // pDict is a borrowed reference
> > >     pDict = PyModule_GetDict(pModule);
> > >
> > >     // pFunc is also a borrowed reference
> > >     pFunc = PyDict_GetItemString(pDict, argv[
> > > 2]);
> > >
> > >     if (PyCallable_Check(pFunc))
> > >     {
> > >         PyObject_CallObject(pFunc, NULL);
> > >     } else
> > >     {
> > >
> > >         PyErr_Print();
> > >     }
> > >
> > >     // Clean up
> > >     Py_DECREF(pModule);
> > >     Py_DECREF(pName);
> > >
> > >     // Finish the Python Interpreter
> > >
> > >     Py_Finalize();
> > >
> > >     return 0;
> > > }
> > >
> > >
> >
> /************************************************************************************************************/
> > >
> > > python file saved as
> > >
> > > py_function.py
> > >
> > >
> > >
> >
> /************************************************************************************************************/
> > >
> > > '''py_function.py - Python source designed to '''
> > > '''demonstrate the use of python embedding'''
> > >
> > > def multiply():
> > >     c = 12345*6789
> > >     print 'The result of 12345 x 6789 :', c
> > >
> > >
> > >
> > >     return c
> > >
> > >
> > >
> >
> /************************************************************************************************************/
> > >
> > > $gcc -g call_function.c  -lpython2.5 -ocall_function
> > > $./call_function py_function.py multiply
> >
> >
> > Shouldn't this be:
> >    $./call_function py_function multiply
> >
> > I.e., you the module name should not have a .py extension.
> >
> > i get following output
> > >
> > > ImportError: No module named py_function
> > > Failed to load "py_function"
> > >
> > > when i kdbg(debug) it i vet NULL value returned from
> PyImport_Import()..
> > >
> > > can any one please find out the error that i am doing.
> > >
> > > --
> > > Shrikant
> > >
> > >
> > > _______________________________________________
> > > C++-sig mailing list
> > > C++-sig at python.org
> > > http://mail.python.org/mailman/listinfo/c++-sig
> > >
> > >
> >
> >
> > --
> > Gustavo J. A. M. Carneiro
> > INESC Porto, Telecommunications and Multimedia Unit
> > "The universe is always one step beyond logic." -- Frank Herbert
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL:
> >
> http://mail.python.org/pipermail/c++-sig/attachments/20071025/0fc3b1ea/attachment-0001.htm
> >
> > ------------------------------
> >
> > _______________________________________________
> > C++-sig mailing list
> > C++-sig at python.org
> > http://mail.python.org/mailman/listinfo/c++-sig
> >
> >
> > End of C++-sig Digest, Vol 51, Issue 25
> > ***************************************
> >
>
>
>
> --
> Shrikant Chikhalkar
> +91 9850991554
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.python.org/pipermail/c++-sig/attachments/20071025/26af7201/attachment.htm
>
> ------------------------------
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
>
> End of C++-sig Digest, Vol 51, Issue 26
> ***************************************
>



-- 
Shrikant Chikhalkar
+91 9850991554
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20071026/48a8be03/attachment.htm>


More information about the Cplusplus-sig mailing list