python - 为什么我不能像 Apple 所说的那样更改系统默认 python?

标签 python macos wxpython

在这个帮助页面上

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/python.1.html

苹果说:

CHANGING THE DEFAULT PYTHON

Using

       % defaults write com.apple.versioner.python Version 2.5

will make version 2.5 the user default when running the both the python and pythonw commands (versioner is the internal name of the version-selection software used).

这根本行不通!

tppllc-Mac-Pro:~ swirsky$ python --version
Python 2.7
tppllc-Mac-Pro:~ swirsky$ defaults write com.apple.versioner.python Version 2.5
tppllc-Mac-Pro:~ swirsky$ python --version
Python 2.7

也没有将 32 位 python 设置为默认值的开关

64-BIT SUPPORT

Version 2.6 supports 64-bit execution (which is on by default). Version 2.5 only supports 32-bit execution.

Like the version of Python, the python command can select between 32 and 64-bit execution (when both are available). Use:

       % defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

to make 32-bit execution the user default (using /Library/Preferences/com.apple.versioner.python will set the system-wide default). The environment variable VERSIONER_PYTHON_PREFER_32_BIT can also be used (has precedence over the preference file):

       % export VERSIONER_PYTHON_PREFER_32_BIT=yes #

Bourne-like shells or

       % setenv VERSIONER_PYTHON_PREFER_32_BIT yes #

C-like shells

我在这里陷入了困境。我正在尝试让 wxpython 运行。但它不会在 Apple Python 2.7 上运行,因为没有 64 位碳支持,而且 wx 中的 cocoa 支持还没有完成。

===更新===

感谢您的帮助!谜底已经揭开。让我感到困惑的一件事是我在我的笔记本电脑(最近的 i5 macbook pro)上运行(32 位)wxpython 没有问题,但它不会在我的台式机(最近的 i7 mac pro)上运行。

他们都有 python 2.7,我认为它们是一样的。但事实并非如此!

Mac Pro 拥有 x86_64 构建

tppllc-Mac-Pro:~ swirsky$ file `which python`
/Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O universal binary with 3 architectures
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture i386):   Mach-O executable i386
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture ppc7400):    Mach-O executable ppc
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64

笔记本电脑没有:

thrilllap-2:thrillscience swirsky$ file `which python`
/Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O universal binary with 2 architectures
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture ppc):    Mach-O executable ppc
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture i386):   Mach-O executable i386

我将在我的台式机上重新安装没有 x86_64 版本的版本,因为我还不需要 64 位支持。

最佳答案

defaults write com.apple.versioner.pythonVERSIONER_PYTHON_PREFER_32_BIT 是 Apple 开发的更改,应用于 Apple 提供的 /usr/bin/python 在 OS X 10.6(Python 2.6.1)中。 (更新:这也适用于 OS X 10.7 Lion。)您可能已经使用 python.org 安装程序之一安装了 Python 2.7。目前可以从 python.org 获得两个 2.7 安装程序,其中一个(适用于 10.5 及更高版本)包括 32 位和 64 位支持。第二个(对于 10.3 及更高版本,包括 10.6)仅为 32 位。据推测,您安装了第一个。要让它在 32 位模式下运行,您可以使用 arch 命令调用它:

$ arch -i386 python2.7

或者,如果您一直想使用 32 位,您可以使用其他安装程序重新安装 2.7。请注意来自 python.org 的 64 位安装程序是 2.7 中的新内容。不幸的是,它存在一些问题,即 Tkinter 和使用它的程序(包括 IDLE)在 OS X 10.6 上失败。这将在维护更新中得到修复。如果您在 10.6 上需要它们,请暂时使用仅 32 位的安装程序。

命令 python 现在调用 2.7 的最可能原因是 python.org 安装程序更新了您的登录配置文件,例如 .bash_profile 将其框架 bin 目录放在第一位在你的 shell 上搜索 PATH

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin: # ...
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ /usr/bin/python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
$ python
Python 2.7 (r27:82508, Jul  3 2010, 21:12:11) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
$ python -c 'import sys;print("%x"%sys.maxint)'
7fffffffffffffff
$ arch -x86_64 python -c 'import sys;print("%x"%sys.maxint)'
7fffffffffffffff
$ arch -i386 python -c 'import sys;print("%x"%sys.maxint)'
7fffffff

关于python - 为什么我不能像 Apple 所说的那样更改系统默认 python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3631108/

相关文章:

cocoa - 在 Mac OS 中设置光标位置

python - 将 Pygame 网络摄像头提要显示到 wxpanel 项中

python - 为什么我的 wxPython 小部件的格式会出现问题?

python - 在 wxPython 中调整面板大小时出现图形问题

python - 从外部 url 打开 txt 文件时出现问题

python - 将格式化字符串转换为二维数组

macos - Brew安装类转储不起作用。如何解决?

python - 线程式 UDP 监听器函数

python - 通过 apache 记录空字节

Android Studio 模拟器 "/dev/kvm is not found"