15

I'm having some trouble in using PyQt/SIP. I guess the SIP is compiled into 64bit, but Python has some problem with finding it.

  File "qtdemo.py", line 46, in 
    import sip
ImportError: dlopen(/Library/Python/2.6/site-packages/sip.so, 2): no suitable image found.  Did find:
        /Library/Python/2.6/site-packages/sip.so: mach-o, but wrong architecture
  • How do I know if a library (so/dylib) is 32bit or 64bit?
  • How do I know if my Python is 32bit or 64bit?
Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
prosseek
  • 182,215
  • 215
  • 566
  • 871
  • 1
    possible duplicate of [Determine if an executable (or library) is 32 -or 64-bits (on OSX)](http://stackoverflow.com/questions/1941825/determine-if-an-executable-or-library-is-32-or-64-bits-on-osx) – outis Jul 07 '12 at 21:16

3 Answers3

17

The file tool can be used to identify executables.

Example:

> file /Applications/TextEdit.app/Contents/MacOS/TextEdit 
/Applications/TextEdit.app/Contents/MacOS/TextEdit: Mach-O universal binary with 2 architectures
/Applications/TextEdit.app/Contents/MacOS/TextEdit (for architecture x86_64):   Mach-O 64-bit executable x86_64
/Applications/TextEdit.app/Contents/MacOS/TextEdit (for architecture i386): Mach-O executable i386
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
  • 1
    While this works for executables, this does not work for libraries. Doug's answer below is correct. (https://stackoverflow.com/a/28856293/930949) – rmcclellan Jun 09 '19 at 00:43
8
lipo -info target/libexample-df07142d9bfd950a.a
input file target/libexample-df07142d9bfd950a.a is not a fat file
Non-fat file: target/libexample-df07142d9bfd950a.a is architecture: x86_64

or

lipo -info `which python`
Non-fat file: /usr/local/bin/python is architecture: x86_64

Don't use file.

Doug
  • 32,844
  • 38
  • 166
  • 222
  • "Don't use `file`." why? – chakrit Oct 02 '15 at 04:40
  • 2
    @chakrit `file` doesn't work on all library types. It guesses formats, so you'll see this: 'libn.a: current ar archive random library' for a static library, where you'll see this from `lipo`: 'Non-fat file: libn.a is architecture: x86_64'. For some file types it works, but why use a tool that *guesses* at filetype using some 'magic tests' (see man file), instead of lipo, the tool that explicitly exists for this purpose? – Doug Oct 05 '15 at 02:36
7

To find the available architectures in the Python instance you are using:

$ file "$( "$(which python)" -c "import sys;print(sys.executable)" )"
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386):    Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc

To find whether the Python is currently running 32-bit or 64-bit (10.6 examples):

$ /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffffffffffff
$ arch -x86_64 /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffffffffffff
$ arch -i386 /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffff
$ arch -ppc /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffff

For python3, substitute sys.maxsize for sys.maxint:

$ python3 -c "import sys;print('%x'%sys.maxsize)"
7fffffff
Ned Deily
  • 83,389
  • 16
  • 128
  • 151