🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

embed Python

Started by
5 comments, last by ReType 21 years ago
Hi! I have problems to use PyRun_SimpleFile(..,..); I have read all docs, i can run from c++ PyRun_SimpleString(..) with out any problems, but when i want to run a file, crash on both debug and release, why? Thanks!
Advertisement
Could you be a bit more descriptive ?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Ok... problem solved, was my faul because i have mix improper thread libs.

Now works to execute PyRun_SimpleFile(..) everithing works but i''m getting some error about "importing site" failure, what''s that?

I need to mention I have get the Python sources and recompile, I have in my programm dir both python.dll and python_d.dll, but not any .py files from "lib"... how can I tell interpreter to look somewhere for this files?

thanks!
site.py (in ''Python22/Lib'' on my machine) is a script that contain site-specific (i.e. machine-specific) configuration, and is implicitely imported everytime python is run.

One reason why python would fail to find it (assuming it exists) could be that the environment variables python relies in are not set. I just looked on my system, no environment variables are set, but there are registry entries, among which


HKLM/Python/PythonCore/2.2/InstallPath C:\Python22
HKLM/Python/PythonCore/2.2/PythonPath C:\Python22\Lib;C:\Python22\DLLs;C:\Python22\Lib\lib-tk


The absence of these keys (especially if you''ve built python yourself and not done a make install at the end, or something equivalent indicated by the INSTALL file) may be the reason why the script files (site.py among them) are not found.


Note that you don''t need python_d.dll unless you are going to debug python itself

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Yes, that''s it, now works.

I use python23_d.dll becouse i need to debug my programm to! and can help me...

But, considering i want to distribuite my programm, there are any way to store the "libs" (i''m referrin some .py files) in a directory and don''t touch PATH variables or registry? I have''t find any way to set-up this... of couse, i don''t want to touch Python sources.

Many thanks!
You need to debug your program, but you don't need to debug the python interpreter internals - you said you didn't want to touch the python source . It is perfectly fine to link the debug version of your program with the release version of the interpreter. I doubt you care following your stack traces inside the library itself

If you plan on redistributing your code, look at

  • the distutils module
  • py2exe which let you encapsulate python apps in an executable package (not exactly what's needed for embedding).
  • Installer, designed to install python applications on machines that do not have python preinstalled.


Note that the last link also contains information on other redistribution tools, as well as advice concerning embedding python (basically : "don't, extend instead" )

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

[edited by - Fruny on June 25, 2003 6:36:40 AM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Many thanks Fruny!

This topic is closed to new replies.

Advertisement