Re: ActivePython: multiple versions on OSX?

Discussion in 'Python' started by Ned Deily, Jul 26, 2011.

  1. Ned Deily

    Ned Deily Guest

    In article <j0l14e$cuh$>, Robert <>
    wrote:

    > Is it possible to install the 2 and 3 series side by side?


    Probably. On Mac OS X, t's certainly possible to install any python.org
    versions side by side, even multiple versions of 2 and 3. That's one of
    the advantages of the Python framework build layout on OS X, which is
    used by both the python.org installers and, I believe, the ActiveState
    installers.

    http://www.python.org/download/

    --
    Ned Deily,
     
    Ned Deily, Jul 26, 2011
    #1
    1. Advertising

  2. Ned Deily

    John Roth Guest

    On Jul 25, 8:18 pm, Ned Deily <> wrote:
    > In article <j0l14e$>, Robert <>
    > wrote:
    >
    > > Is it possible to install the 2 and 3 series side by side?

    >
    > Probably.  On Mac OS X, t's certainly possible to install any python.org
    > versions side by side, even multiple versions of 2 and 3.  That's one of
    > the advantages of the Python framework build layout on OS X, which is
    > used by both the python.org installers and, I believe, the ActiveState
    > installers.
    >
    > http://www.python.org/download/
    >
    > --
    >  Ned Deily,
    >  


    When you do, you might also want to look at PEP 394:
    http://www.python.org/dev/peps/pep-0394/

    It can simplify writing scripts which select the version you want.

    John Roth
     
    John Roth, Jul 26, 2011
    #2
    1. Advertising

  3. Ned Deily

    Web Dreamer Guest

    John Roth a écrit ce mardi 26 juillet 2011 14:00 dans <75342033-
    > :

    > On Jul 25, 8:18 pm, Ned Deily <> wrote:
    >> In article <j0l14e$>, Robert <>
    >> wrote:
    >>
    >> > Is it possible to install the 2 and 3 series side by side?

    [...]
    > When you do, you might also want to look at PEP 394:
    > http://www.python.org/dev/peps/pep-0394/
    >
    > It can simplify writing scripts which select the version you want.


    http://www.python.org/dev/peps/pep-0394/#impact-on-python-environment-variables
    What would be a nice feature would be having:
    PYTHONPATH (and PYTHONHOME, etc) referring to all versions, and to allow
    having PYTHON2PATH, PYTHON2HOME (and PYTHON3PATH, PYTHON3HOME), etc... for
    the specific versions.
    This would allow having global variables for all versions, and special
    variables for specific versions, to allow more flexibility.
    Or would it be silly?

    --
    Web Dreamer
     
    Web Dreamer, Jul 26, 2011
    #3
  4. On Wed, Jul 27, 2011 at 2:33 AM, Melton Low <> wrote:
    > It's probably impractical.  You would need a pair for each version of Python
    > installed, ie. (PYTHON26PATH,PYTHON26HOME) for 2.6.x,
    > (PYTHON27PATH,PYTHON27HOME) for 2.7.x, .... for 3.1.x, for 3.2.x, etc).


    You could set up a script for each version that looks for environment
    variables in the right order, stopping when it finds one. Version
    3.2.1 would look for PYTHON321PATH, then PYTHON32PATH, then
    PYTHON3PATH, finally falling back on PYTHONPATH. It could then put the
    appropriate path into PYTHONPATH (not overwriting the external
    variable of the same name - if your shell doesn't do that for you,
    just save it to restore later), and invoke Python.

    Still seems fairly cumbersome, and doesn't handle the possibility of
    having two separate installs of the same version number (different
    builds of 3.3, or 32-bit and 64-bit Pythons, or something). It may be
    easier to simply create some scripts that set up the environment
    explicitly, and then invoke Python. Name 'em according to what you
    want of them.

    ChrisA
     
    Chris Angelico, Jul 26, 2011
    #4
  5. Ned Deily

    Ned Deily Guest

    In article
    <>,
    Melton Low <> wrote:
    [...]
    > On Mac OS X, a link is automatically installed in /usr/local/bin for each
    > version of the Python executables, ie python2.7 for the 2.7.x and python3.2
    > for 3.2.x. Just invoke your script with the appropriate Python version.
    > eg. python3.2 yourscript to run 'yourscript'.


    Yes, the default action for the python.org OS X installers is to install
    the /usr/local/bin version specific links. However, that is not a
    complete solution for managing framework versions. The main problem is
    that, again by default, Distutils-packaged scripts are installed into
    the framework bin directory. This means there is no ambiguity or
    conflict among the same package/script installed in different versions
    of Python - a good thing - but it also means the proper way to manage
    which Python is invoked by `python` or by `python3` (and `python2 in the
    future when PEP 394 is approved and implemented) is by ensuring the
    desired "primary" version's framework bin directory comes first on the
    shell PATH environment variable. The python.org installers provide a
    script to do that, although somewhat crudely.

    Let's say I've used the python.org 2.6, 2.7, and 3.2 installers (and
    deselected the option to automatically update the shell scripts) and
    then use Distribute to install easy_install into those instances. There
    is also an Apple-supplied Python 2.6 and easy_install (and
    easy_install-2.6) in /usr/bin.

    $ curl -O http://python-distribute.org/distribute_setup.py
    $/usr/local/bin/python2.6 distribute_setup.py
    $/usr/local/bin/python2.7 distribute_setup.py
    $/usr/local/bin/python3.2 distribute_setup.py
    $ echo $PATH
    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    $ which python python2.6 python2.7
    /usr/bin/python
    /usr/bin/python2.6
    /usr/local/bin/python2.7
    $ which easy_install easy_install-2.6 easy_install-2.7
    /usr/bin/easy_install
    /usr/bin/easy_install-2.6
    # note that there is no access to the easy_install-2.7
    # nor to the correct easy_install-2.6 for the python.org 2.6

    $ open /Applications/Python\ 2.6/Update\ Shell\ Profile.command
    $ bash -l
    $ echo $PATH
    /Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/
    sbin:/sbin:/usr/local/bin:/usr/X11/bin
    $ which python python2.6 python2.7
    /Library/Frameworks/Python.framework/Versions/2.6/bin/python
    /Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
    /usr/local/bin/python2.7
    $ which easy_install easy_install-2.6 easy_install-2.7
    /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install
    /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install-2.6

    $ open /Applications/Python\ 2.7/Update\ Shell\ Profile.command
    $ bash -l
    $ echo $PATH
    /Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks
    /Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/loc
    al/bin:/usr/X11/bin
    $ which python python2.6 python2.7
    /Library/Frameworks/Python.framework/Versions/2.7/bin/python
    /Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
    /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
    $ which easy_install easy_install-2.6 easy_install-2.7
    /Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install
    /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install-2.6
    /Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install-2.7

    # Now "easy_install" refers to the 2.7 version just as "python" does.

    Python 3 instances work similarly although, since Apple does not yet
    ship a system Python 3, there is no conflict with /usr/bin and the
    Python 3 framework bin directories include "python3" links instead of
    "python" ones, so there is also no conflict with Python 2 instances.

    $ open /Applications/Python\ 3.2/Update\ Shell\ Profile.command
    $ bash -l
    $ echo $PATH
    /Library/Frameworks/Python.framework/Versions/3.2/bin:/Library/Frameworks
    /Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/V
    ersions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    $ which python python2.6 python2.7 python3 python3.2
    /Library/Frameworks/Python.framework/Versions/2.7/bin/python
    /Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
    /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
    /Library/Frameworks/Python.framework/Versions/3.2/bin/python3
    /Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2
    $ which easy_install easy_install-2.6 easy_install-2.7 easy_install-3.2
    /Library/Frameworks/Python.framework/Versions/3.2/bin/easy_install
    /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install-2.6
    /Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install-2.7
    /Library/Frameworks/Python.framework/Versions/3.2/bin/easy_install-3.2

    But here is a potential gotcha! Distribute does not provide a
    "easy_install3" link when installing into a Python 3 instance so now the
    unversioned "easy_install" command refers to the Python 3.2 version,
    which may not be what you expected. You can change the search order of
    PATH:

    $ export
    PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frame
    works/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framew
    ork/Versions/3.2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X1
    1/bin
    $ which easy_install easy_install-2.6 easy_install-2.7
    easy_install-3.2/Library/Frameworks/Python.framework/Versions/2.7/bin/eas
    y_install
    /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install-2.6
    /Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install-2.7
    /Library/Frameworks/Python.framework/Versions/3.2/bin/easy_install-3.2

    To make this change permanent, you would need to edit the appropriate
    shell startup file, for example, .bash_profile. Or be careful about the
    order in which you run the Update Shell Profile commands in the first
    place.

    When in doubt, you can always use the version-specific name (in this
    case that works but most Python packages do not provide version specific
    links) or you can use an absolute path. There are, of course, other
    strategies for dealing with the third-party packages in case of
    ambiguities, for example using virtualenvs or using Distutils alternate
    installation options, like --home.

    The situation gets more complex if you have installed Pythons from
    distributors other than python.org; these may be installed in the same
    or in different locations and may or may not be framework builds. But
    the general principles still apply.

    The current state is not ideal, especially for new users of Python. I'm
    hoping we can make life a bit easier by the time 3.3 is released next
    year.

    --
    Ned Deily,
     
    Ned Deily, Jul 26, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trent Mick
    Replies:
    4
    Views:
    788
    Trent Mick
    Nov 1, 2003
  2. Thomas Heller
    Replies:
    2
    Views:
    302
    Thomas Heller
    Nov 4, 2003
  3. Hoang
    Replies:
    4
    Views:
    555
    Trent Mick
    Dec 15, 2003
  4. Trent Mick
    Replies:
    3
    Views:
    469
  5. Robert
    Replies:
    0
    Views:
    158
    Robert
    Jul 26, 2011
Loading...

Share This Page