简体   繁体   English

在Mac OSX上更改python 2.6.6的环境变量

[英]Changing environmental variable for python 2.6.6 on Mac OSX

I am trying to add an environmental variable, but by default my computer has installed Python 2.7. 我正在尝试添加一个环境变量,但默认情况下我的计算机已经安装了Python 2.7。

I changed the default using: 我改变了默认值:

defaults write com.apple.versioner.python Version 2.6 defaults write com.apple.versioner.python Version 2.6

I am now trying to change an environmental variable using: 我现在正尝试使用以下方法更改环境变量:

nano ~/.bash_profile nano~ / .bash_profile

But that is for Python 2.7. 但这适用于Python 2.7。

How do I change the environmental variable for 2.6? 如何更改2.6的环境变量?

Thanks! 谢谢!

As the man page explains, if you want to set an environment variable to make python default to 2.6, it's VERSIONER_PYTHON_VERSION . 正如手册页所解释的,如果你想设置一个环境变量使python默认为2.6,那就是VERSIONER_PYTHON_VERSION

So, in your .bash_profile , add this line: 因此,在.bash_profile ,添加以下行:

export VERSIONER_PYTHON_VERSION=2.6

However, there's very rarely a good reason to do this. 但是,很少有理由这样做。 You can always run the version you want explicitly: 您始终可以显式运行所需的版本:

$ 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

… and use a shebang line in your script to do the same: ...并在脚本中使用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)]

More importantly, there's not that much code out there that works with 2.6 but not 2.7. 更重要的是,没有那么多代码可以使用2.6而不是2.7。 In particular, the reason you want this is because "I am trying to use the Echo Nest Remix package which apparently only works with 2.66 and not 2.7", but the docs say it works with all versions from 2.5 to 2.7, and explicit suggest 2.7 as the best version. 特别是,你想要这个的原因是因为“我正在尝试使用Echo Nest Remix软件包,它显然只适用于2.66而不是2.7”,但文档说它适用于2.5到2.7的所有版本,并且明确建议2.7作为最好的版本。 The default Mac binary installer here only works in 2.7. 默认的Mac二进制安装包在这里只适用于2.7。 If you prefer to install from source, the docs say to use pip or easy_install with whichever Python is the default on your system. 如果您更喜欢从源代码安装,那么文档会说使用pipeasy_install与系统上的默认Python。

You should use virtualenv to create an isolated Python environment, with whatever version of the interpeter you like. 您应该使用virtualenv创建一个独立的Python环境,使用您喜欢的任何版本的interpeter。 It will make your life a lot easier. 它会让你的生活更轻松。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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