platform.architecture, __path__, PYTHONPATH, and dist.utils

szager at szager at
Fri Apr 3 19:51:08 CEST 2009


I need to support both 32-bit and 64-bit versions of compiled python
modules that cannot be installed into the default search path of the
python interpreter(s).  I use PYTHONPATH to point to the module
installations, but I have a problem: I don't know, a priori, whether
the user will be running a 32-bit or 64-bit python interpreter.  So, I
would like to set up a hybrid installation that will be able to load
either version, based on the architecture of the currently-running

** How can I use dist.utils to create a hybrid installation of an
extension module? **

Currently, I'm manually hacking the build results, but my method is
very platform-dependent.  It would be nicer to have an automated,
platform-agnostic way to do this.

Here's what I'm doing now:


In /path/to/foo/

import os
import platform

# Note that I can't use platform.architecture(),
#   because that doesn't work when using embedded python
exe_arch = platform.architecture('/proc/self/exe')

__path__[0] = os.path.join(__path[0]__, exe_arch[0])

from libfoo import *

Thanks in advance,

Stefan Zager

More information about the Python-list mailing list