0

Request: could someone post a recipe, from top to bottom, for creating an Xcode project that will compile C code to build a Python extension? I've seen several posts here that touch upon the subject, but they seem confusing and incomplete, and they disagree.

Specific questions:

  1. Can Mac Python 2.7 load a .dylib? Mine coldly ignores them.

  2. Can one really solve the problem by renaming a .dylib to a .so filename extension? Various posts disagree on this question.

  3. Are .dylib and .so actually different formats? Are there settings I could make in Xcode to make it output a true .so format?
  4. If Python is failing to load an extension file, are there tools to diagnose it? Is there any way to poke into the file, look at its format, and see if it does or does not match what is needed?

  5. When I renamed my .dylib to .so, I got the following error message:

ImportError: dlopen(/Library/Python/2.7/site-packages/pypower.so, 2): no suitable image found. Did find: /Library/Python/2.7/site-packages/pypower.so: mach-o, but wrong architecture

My project is targeted to "32-bit Intel" architecture. And I really need to use 32-bit, because of some of the old libraries I'm linking to. Is Python going to have a problem loading a 32-bit library? Is there a way to bridge the gap?

Joymaker
  • 813
  • 1
  • 9
  • 23
  • BTW, export VERSIONER_PYTHON_PREFER_64_BIT=no export VERSIONER_PYTHON_PREFER_32_BIT=yes in .bash_profile didn't help. – Joymaker Jul 21 '14 at 23:54

1 Answers1

1

The Python executable in current versions of Mac OS X is 64-bit only, so any extensions it loads must also be 64-bit. If your libraries are only available for 32-bit systems, you will be unable to link to it from a Python extension. One possible solution might be to have a separate 32-bit executable that loads the library, then communicate with that executable from your Python extension.

  • I'm on 10.7.5. How hard would it be to build a 32-bit Python from source? Sounds like that's my last best shot at a solution. – Joymaker Jul 24 '14 at 00:26