What files are required for Py_Initialize to run?

Posted on

Question :

What files are required for Py_Initialize to run?

I am working on a simple piece of code that runs a Python function from a C/C++ application. In order to do this I set the PYTHONPATH and run initialize as follows:

Py_SetPythonHome("../Python27");
Py_InitializeEx(0);

Then I import my module and run my function. It works great.

I am now attempting to build an installer for my colleagues to run my code. I want to minimize the number of files I need to include in this installer, for obvious reasons.

Googling around the subject tells me that I should be able to include the files “Python27.lib” and “Python27.dll”, then zip the “DLLs” and “Lib” folders and include them. However, when I attempt this, Py_Initialize fails.

A quick examination of what is causing this failure shows that Py_Initialize appears to depend upon a number of .pyc files in the Lib folder including (but not limited to warnings.pyc, _abcoll.pyc, _future_.pyc and the contents of the “encodings” folder.

I cannot understand why this would be. Any advice?

Asked By: Matt McC

||

Answer #1:

At the beginning, I wanted to say that there’s no module required (at least no non-builtin one) for Py_InitializeEx, so the only requirement was python27.dll (btw: python27.lib is not required, unless your colleagues want to link something against it – but that wouldn’t be very easy w/o Python‘s Include dir). I had this code (BTW: I am using Python 2.7.10 that I built using VStudio 10 (2010)):

#include <stdio.h>
#include <conio.h>
#include <Python.h>

int main() {
int i = 0;
char *pyCode =
"s = "abc""n""

Leave a Reply

Your email address will not be published.