强制使用 32 位 python
我在为我的 macports python2.7 触发 32 位 python 时遇到一些问题
calvins-MacBook ttys003 Tue Nov 01 01:04:23 |~|
calvin$ arch -arch x86_64 python
Python 2.7.2 (default, Oct 31 2011, 20:10:35)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.10.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform; platform.architecture()
('64bit', '')
>>> exit()
calvins-MacBook ttys003 Tue Nov 01 01:04:49 |~|
calvin$ arch -arch i386 python
Python 2.7.2 (default, Oct 31 2011, 20:10:35)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.10.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform; platform.architecture()
('64bit', '')
>>>
我应该如何触发 32 位 python 的使用?
I am having some trouble triggering the 32-bit python for my macports python2.7
calvins-MacBook ttys003 Tue Nov 01 01:04:23 |~|
calvin$ arch -arch x86_64 python
Python 2.7.2 (default, Oct 31 2011, 20:10:35)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.10.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform; platform.architecture()
('64bit', '')
>>> exit()
calvins-MacBook ttys003 Tue Nov 01 01:04:49 |~|
calvin$ arch -arch i386 python
Python 2.7.2 (default, Oct 31 2011, 20:10:35)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.10.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform; platform.architecture()
('64bit', '')
>>>
How should I go about triggering the use of 32-bit python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将以 32 位模式运行二进制文件(这就是您所做的)。
如果您通过 MacPorts 安装了 Python,请检查它是否实际上是使用 32 位和 64 位(通用二进制)构建的。
这是我的输出:
如果您没有看到
i386
,那么您的版本没有 32 位版本。不过,如果您可以运行 arch -i386 python 应该没问题,因为如果您的二进制文件无法运行 32 位模式,您将会收到错误消息。
另外,不要依赖
platform.architecture()
来告诉您它是否是 32 位,因为即使您使用的是 32 位,通用二进制文件也会报告 64 位模式。最好依赖sys.maxsize
,它会根据您处于 32 位还是 64 位模式而变化。Python 32 位模式,注意 sys.maxsize > 2**32:
64位模式下的Python:
Will run the binary in 32-bit mode (which is what you did).
If you installed Python via MacPorts, check that it was actually built with 32-bit and 64-bit (universal binary).
This is output on mine:
If you don't see the
i386
, then you your version doesn't have a 32-bit build.Though if you can run
arch -i386 python
you should be fine, since you will get an error if your binary can't run 32-bit mode.Also, do not rely on
platform.architecture()
to tell you if it's 32-bit, because universal binaries will report 64-bit mode even if you're in 32-bit. It's better to rely onsys.maxsize
, which changes depending on if you're in 32-bit or 64-bit mode.Python in 32-bit mode, notice
sys.maxsize > 2**32
:Python in 64-bit mode: