简体   繁体   中英

How to check if a library is 32bit/64bit built on Mac OS X?

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?

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
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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM