Search code examples
pythonembedpython-c-api

C++ Python embedding: Run on machine with no Python?


I'm trying to make a small game that supports Python scripting. I've no problems with using the Python C-API, but I don't know how to ensure that the game will run on a computer with no Python installed.

I know I need pythonXY.dll -- what else is there? When I try to run the program it tells me it cannot find encodings.utf_8. I tried copying the encodings/utf_8.py file in the same directory as my program, but the error still pops up.


Solution

  • You need the encodings/__init__.py file, otherwise encodings is a folder and not a python package.

    Chances are that you'll need a lot of stuff from within the python standard library. To make everything just work you'll need to include the entire standard library along with your program.

    You can make this a bit better by putting the library in a zip file and adding that to sys.path. Also, you can include only pyc not the original py files.