How to chose python executable if several exist?

如何选择python可执行如果几个存在吗?

问题 (Question)

I would like to execute Python scripts using the Python/C API (I am using Mac OS X Mavericks, Xcode). Since multiple Python distributions are installed on my machine (System, Homebrew, several virtualenvs), how can I define which to use?

我想执行Python脚本使用Python / C API(我使用Mac OS X小牛,Xcode)。因为多个Python发行版安装在我的机器上(系统,家酿,几个virtualenv),如何定义来使用?

最佳答案 (Best Answer)

You can define which one to use either:

  • by specifying the fullpath to the executable ;
  • or with different aliases.

For example, I have both Python 2.7 and Python 3.2 on this machine:

$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

$ python3
Python 3.2.3 (default, Jul 23 2012, 16:48:24)
[...]

$ /usr/bin/python2.7
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[...]

$ /usr/bin/python3.2
Python 3.2.3 (default, Jul 23 2012, 16:48:24)
[...]

您可以定义要使用哪一种:

  • 通过指定fullpath可执行;
  • 或与不同的别名。

例如,我这台机器上都有Python 2.7和Python 3.2:

$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

$ python3
Python 3.2.3 (default, Jul 23 2012, 16:48:24)
[...]

$ /usr/bin/python2.7
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[...]

$ /usr/bin/python3.2
Python 3.2.3 (default, Jul 23 2012, 16:48:24)
[...]

本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:http://stackoverflow.com/questions/22080674