question; C/C++ with Python

H

Hongtian

Hi friends,

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.

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? How to do that? should I
copy all pythons libs to my C/C++ application directory? That could be
terrible...

Thanks.
 
G

Gabriel Genellina

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top