wxPyCoreAPI_IMPORT() failing

I'm working on updating an archaic program to be somewhat more modern.
It's a C++ program with embedded Python 2.5 using wxPython. I
downloaded wxPython 2.7 and the Windows development files to build and
link against. The program compiled without complaint, but I've had
difficulty getting it to run.

The first problem I ran into was a missing msvcp90.dll/msvcr90.dll
file, which I'd guess (not being familiar with Windows build
processes) is because wxPython was built with a different version of
Visual Studio than I'm using (I'm on 2010 here). I found copies of
those files elsewhere on my computer and copied them into place. Then
I got R6034 errors complaining that something was trying to load the C
runtime incorrectly. I fixed *that* with a simple script that uses
mt.exe to embed each of the .manifest files in the vc_dll directory of
the development files into their respective DLL files, as per these
links:
http://msdn.microsoft.com/en-us/library/ms235560(v=vs.80).aspx
http://msdn.microsoft.com/en-us/library/ms235591(v=vs.80).aspx

Now my issue is that wxPyCoreAPI_IMPORT() isn't successful. I have no
insight into *why* it's unsuccessful; as far as I can tell there's no
error logging, just a failed function call. PyErr_Print() doesn't do
anything, and PyErr_Occurred() returns 0. So that's a bit weird.
Here's the relevant code from the program (and apologies for the
schizophrenic indenting, which I haven't gotten around to fixing yet):

  PyEval_InitThreads();
  printf("InitThreads done\n");
  if ( ! wxPyCoreAPI_IMPORT() ) {
    printf("PyCoreAPI import failed\n");
    PyErr_Print();
    printf("%d\n", PyErr_Occurred());
    wxSleep(30);
  Py_Finalize();
  return false;
  }

And the output:

InitThreads done
PyCoreAPI import failed
0

I'll freely admit that the "build environment" for this program is
pretty funky, so my first inclination is to assume that I've set
something up incorrectly. However it's rather hard for me to guess
what is wrong when I have no information to go on beyond "It doesn't
work." Any ideas?

-Chris

Chris wrote:

I'm working on updating an archaic program to be somewhat more modern.
It's a C++ program with embedded Python 2.5 using wxPython. I
downloaded wxPython 2.7 and the Windows development files to build and
link against. The program compiled without complaint, but I've had
difficulty getting it to run.

The first problem I ran into was a missing msvcp90.dll/msvcr90.dll
file, which I'd guess (not being familiar with Windows build
processes) is because wxPython was built with a different version of
Visual Studio than I'm using (I'm on 2010 here).

That's the root of your problem. All of your tools need to use the same
compiler. Python 2.5 and wxPython 2.7 were built with Visual Studio
2008. If you want to embed it reliably, you'll need to use that
compiler. Otherwise, you're mixing versions of the run-time library.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

…bah, OK. I got my version numbers mixed up a bit, by the way – I’m trying to update to Python 2.7, using WxPython 2.8.12.0 built for Python 2.7. But it looks like the Visual Studio version is still a problem. Thanks.

-Chris

···

On Tue, May 3, 2011 at 10:37 AM, Tim Roberts timr@probo.com wrote:

Chris wrote:

I’m working on updating an archaic program to be somewhat more modern.

It’s a C++ program with embedded Python 2.5 using wxPython. I

downloaded wxPython 2.7 and the Windows development files to build and

link against. The program compiled without complaint, but I’ve had

difficulty getting it to run.

The first problem I ran into was a missing msvcp90.dll/msvcr90.dll

file, which I’d guess (not being familiar with Windows build

processes) is because wxPython was built with a different version of

Visual Studio than I’m using (I’m on 2010 here).

That’s the root of your problem. All of your tools need to use the same

compiler. Python 2.5 and wxPython 2.7 were built with Visual Studio

  1. If you want to embed it reliably, you’ll need to use that

compiler. Otherwise, you’re mixing versions of the run-time library.

I thought Python 2.5 was compiled with VS2003 and then 2.6+ was compiled with VS2008

Yes, but I got my version numbers mixed up. We’re migrating from Python 2.5 to Python 2.7; I said I was using wxPython 2.7 but what I meant was “I’m using the most recent wxPython built for use in Python 2.7, which by implication means that I’m also using Python 2.7.” Poorly phrased, and my apologies.

In any event, the program works now! Thanks for your help, Tim.

-Chris

···

On Tue, May 3, 2011 at 11:54 AM, Mike Driscoll kyosohma@gmail.com wrote:

I thought Python 2.5 was compiled with VS2003 and then 2.6+ was compiled with VS2008

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Mike Driscoll wrote:

I thought Python 2.5 was compiled with VS2003 and then 2.6+ was
compiled with VS2008

Yes, he didn't write what he meant, and I read exactly what I wanted to
read. He's really using Python 2.7 and wxPython 2.8. The reference to
msvcp90.dll is enough to confirm that it is VS2008.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

I understand that msvcp90.dll goes with VS2008. I was just confused by your statement: “Python 2.5 and wxPython 2.7 were built with Visual Studio
2008.”

No big deal.

  • Mike

Mike Driscoll wrote:

I understand that msvcp90.dll goes with VS2008. I was just confused by
your statement: "Python 2.5 and wxPython 2.7 were built with Visual
Studio 2008."

There was more than enough confusion to go around. Your statement was
quite correct.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Since you are embedding Python and wxPython in your C++ app then you have another option if you really must use VS 2010 for some reason. You can do it if you build your own Python, wxWidgets and wxPython instead of using the downloadable binaries. That does significantly increase the complexity of your builds, but it is possible.

···

On 5/3/11 10:41 AM, Chris Weisiger wrote:

...bah, OK. I got my version numbers mixed up a bit, by the way -- I'm
trying to update to Python 2.7, using WxPython 2.8.12.0 built for Python
2.7. But it looks like the Visual Studio version is still a problem. Thanks.

--
Robin Dunn
Software Craftsman