Search code examples
pythonpython-c-api

How to chose python executable if several exist?


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?


Solution

  • 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)
    [...]