15

我在使用 PyQt/SIP 时遇到了一些麻烦。我猜 SIP 是编译成 64 位的,但是 Python 在查找它时遇到了一些问题。

  文件“qtdemo.py”,第 46 行,在
    进口小口
ImportError: dlopen(/Library/Python/2.6/site-packages/sip.so, 2): 找不到合适的图像。发现:
        /Library/Python/2.6/site-packages/sip.so:mach-o,但架构错误
  • 我如何知道库 (so/dylib) 是 32 位还是 64 位?
  • 如何知道我的 Python 是 32 位还是 64 位?
4

3 回答 3

17

file工具可用于识别可执行文件。

例子:

> 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
于 2010-07-08T19:35:21.350 回答
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

或者

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

不要使用file.

于 2015-03-04T13:56:25.100 回答
7

要在您正在使用的 Python 实例中查找可用架构:

$ 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

要查找 Python 当前运行的是 32 位还是 64 位(10.6 示例):

$ /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

对于 python3,替换sys.maxsizesys.maxint

$ python3 -c "import sys;print('%x'%sys.maxsize)"
7fffffff
于 2010-07-08T20:00:41.370 回答