[Pythonmac-SIG] Easy way to avoid Fatal Python error: Interpreter not initialized (version mismatch?)

Ronald Oussoren ronaldoussoren at mac.com
Wed Jul 25 21:33:28 CEST 2007


On 25 Jul, 2007, at 18:46, Ivan Vilata i Balaguer wrote:

> I've been looking for some hours for a more-or-less easy solution or
> workaround to the
>
>    Fatal Python error: Interpreter not initialized (version mismatch?)
>    Abort trap
>
> error that didn't imply uninstalling additional Pythons and the  
> like, so
> I'm posting this here so at least people can find it when googling for
> it. ;)  Quite surely not the best solution, but it looks quite simple.
>
> The problem comes from an extension being linked against the *default*
> Python (i.e. the one which pops up when running ``python``) instead of
> the requested one.  When using GCC with ``-framework Python``, it
> accesses the Python framework in ``/Library/Frameworks/ 
> Python.framework``,
> and it uses some components right under it which happen to be links to
> paths under ``Versions/Current``, which is linked to the default
> version.  In fact, when you inspect the extension which fails to load
> with ``otool -L EXTENSION.so`` you can see it's linked with the wrong
> Python library.

Your instructions are technically valid, but...

The right way (TM) to fix this is to change the project that uses '- 
framework Python' to link extensions because that is not the  
recommended way to link extensions on OSX. The best way to build  
extensions is using distutils, but that isn't always convenient in a  
large project that already has a different build infrastructure. In  
that case I'd copy the link flags used by distutils into the existing  
build infrastructure.

Note that there are several reasons why linking with the python  
framework is a bad idea:
1) "-framework" doesn't actually work correctly when you want to link  
with a version other than the "Current" one
2) When you link with a framework (or other dynamic library) the full  
path to that library is embedded in the extensions. This means you  
cannot reuse the extension between python installations in different  
locations (e.g. /System/Library/Python, /Library/Python and /opt/ 
python, assuming all are using the same major release of python). You  
might not want to do this yourself, but that is something to keep in  
mind when distributing binary eggs.

BTW. You're instructions aren't quite clear on this, but it is always  
a bad idea to use extensions compiled for one major release of python  
(2.X) with some other major release (2.Y). Using an extension of 2.X  
with 2.X+1 tends to work, but there is no guarantee for binary  
compatibility between major releases of Python.

Ronald
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3562 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20070725/119c6a44/attachment.bin 


More information about the Pythonmac-SIG mailing list