【问题标题】:Changing environmental variable for python 2.6.6 on Mac OSX在 Mac OSX 上更改 python 2.6.6 的环境变量
【发布时间】:2013-10-30 17:03:37
【问题描述】:

我正在尝试添加环境变量,但默认情况下我的计算机已安装 Python 2.7。

我改变了默认使用:

默认写入 com.apple.versioner.python 版本 2.6

我现在正在尝试使用以下方法更改环境变量:

纳米~/.bash_profile

但这适用于 Python 2.7。

如何更改 2.6 的环境变量?

谢谢!

【问题讨论】:

  • 什么样的环境变量需要 Python 2.6.6 而不是 2.7?
  • 我正在尝试使用显然只适用于 2.66 而不是 2.7 的 Echo Nest Remix 包
  • 谁告诉你 Echo Nest Remix 只适用于 2.6.6?

标签: python macos python-2.7 python-2.6


【解决方案1】:

正如the man page 解释的那样,如果你想设置一个环境变量使python 默认为2.6,那就是VERSIONER_PYTHON_VERSION

所以,在您的.bash_profile 中,添加这一行:

export VERSIONER_PYTHON_VERSION=2.6

但是,很少有这样做的充分理由。您始终可以明确运行您想要的版本:

$ python2.6
Python 2.6.8 (unknown, Aug 25 2013, 00:04:29)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D

...并在脚本中使用 shebang 行来做同样的事情:

$ cat <<EOF >test26.py
> #!/usr/bin/env python2.6
> import sys
> print sys.version
> ^D
$ chmod +x test26.py
$ ./test26.py
2.6.8 (unknown, Aug 25 2013, 00:04:29)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]

更重要的是,没有那么多代码适用于 2.6 而不是 2.7。特别是,你想要这个的原因是因为“我正在尝试使用显然只适用于 2.66 而不是 2.7 的 Echo Nest Remix 包”,但文档说它适用于从 2.5 到 2.7 的所有版本,并明确建议 2.7作为最好的版本。默认的 Mac 二进制安装程序 here 仅适用于 2.7。如果您更喜欢从源代码安装,文档说使用 pipeasy_install 与您系统上的默认 Python。

【讨论】:

    【解决方案2】:

    您应该使用virtualenv 创建一个隔离的 Python 环境,使用您喜欢的任何版本的解释器。它会让你的生活更轻松。

    https://pypi.python.org/pypi/virtualenv

    【讨论】:

      猜你喜欢
      • 2016-07-07
      • 1970-01-01
      • 2016-06-25
      • 2013-07-05
      • 2014-12-08
      • 1970-01-01
      • 2013-01-24
      • 2020-07-12
      • 2011-08-21
      相关资源
      最近更新 更多