question; C/C++ with Python
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Dec 25 16:29:14 EST 2008
En Thu, 25 Dec 2008 12:50:31 -0200, Hongtian <hongtian.info at gmail.com>
escribió:
> I have a C/C++ application and I wrote a .py file to extend it.
> The .py file includes some simple functions without import any other
> modules.
And you embedded the Python interpreter into your application, I presume?
> Today, I want to update my .py file and import SMTP library in the
> file, but it seems fail to import SMTP library.
>
> So I want to ask: when the .py file is used to extend C/C++
> application, can it import other modules?
Sure! Just make sure the desired modules can be found along the Python
search path (that is, sys.path)
> How to do that? should I
> copy all pythons libs to my C/C++ application directory? That could be
> terrible...
If you want to distribute your application, this would be a good thing,
else you must rely on the right Python version being installed somewhere.
You may add the required entries to sys.path manually, in your code. Or
you may define the PYTHONPATH environment variable (also in your code)
before initializing the interpreter. Or you may call the function
Py_SetProgramName (before initializing) pointing to your external Python
installation.
--
Gabriel Genellina
More information about the Python-list
mailing list