Installed Python 3.1. Terminal still launches 2.5.1.

Discussion in 'Mac Programming' started by Caezar, Aug 7, 2009.

  1. Caezar macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #1
    Thread title says it all :D

    I installed Python 3.1, but when I type python in the terminal, it launches python 2.5.1.

    Can the two version coexist?
    Can I uninstall 2.5.1?
    If I can, should I?
     
  2. iShater macrumors 604

    iShater

    Joined:
    Aug 13, 2002
    Location:
    Chicagoland
    #2
    Yes they can. Most likely each one went to a directory that has the version number in it's name.

    Which one is in your PATH? that would be the one that gets launched.
     
  3. Caezar thread starter macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #3
    What do you mean by my Path?
     
  4. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #4
    In the Terminal, type echo $PATH and see if there's any Python references there.
     
  5. Caezar thread starter macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #5
    This is what I get:
    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
     
  6. GroovyLinuxGuy macrumors regular

    GroovyLinuxGuy

    Joined:
    Apr 2, 2006
    Location:
    Canada
    #6
    The PATH is an environment variable that is a list of directories that the operating system looks in to find commands issued by the user

    You may have to look where python was installed and use the full path to that version
    The default version on python is found at /usr/bin/python (actually that's just a symlink to /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python)

    Depending on how you installed it you might want to check /usr/bin or even easier do a
    locate python | less
    in the terminal and just look for where it was installed

    You can then use
    #!/usr/bin/python3.1 (or where ever your interpreter is located)
    on your shebang line

    Personally I create an /opt directory and install any newer versions there and just symlink it back to /usr/bin but that's just me :)

    Cheers and I hope that made sense...still working on first morning coffees
     
  7. Caezar thread starter macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #7
    Thanks.

    Python 2.x is installed under /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/

    Python 3.x is installed under Macintosh HD/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/

    Is there a way I can open the newer version from the terminal?
     
  8. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #8
    There are many ways. I would probably recommend (as the system probably likes 2.3 a lot) adding a symlink to /usr/local/bin called py3 or python3 or something like that like this:
    sudo ln -s "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/python" /usr/local/bin/py3
    The path to the 3.1 python executable might not be quite right, so you can just sub it in.

    Then when you want to use version 3, you'd just type py3. When you wanted the 2.3, just type python. I would not change, at the system level, which one gets called by default. If you really, really want to get version 3 by typing python, you could add an entry to your bath by editing your .bash_profile, like:
    export PATH=/my/new/dir:$PATH

    Then you can make a symlink called python in /my/new/dir. That way, when you ran python from the terminal it would find the version 3 executable before it found the version 2 one. I think this would let the system still use the python it likes by name, but someone may need to correct me on this.

    -Lee
     
  9. Caezar thread starter macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #9
    Ok, I am out of my depth here. I'll forget the terminal and simply use IDLE.

    Thanks everyone for you help. I learned a few things on the way.
     
  10. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #10
    The Python 3.1 Mac installer comes with a shell script which makes it the default Python to use on the Mac. Just run that and you will be sorted.
     
  11. Caezar thread starter macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #11
    Are you referring to Update Shell Profile.command? I ran it to no avail.
     
  12. Cinder6 macrumors 6502

    Cinder6

    Joined:
    Jul 9, 2009
    #12
    How did you install it? Did you download a package, or use MacPorts? Did you try typing 'python31'?
     
  13. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #13
    Sometimes you need to log out and log back in again for changes to the path to take effect. Try that.
     
  14. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #14
    A simple restart of the Terminal is often all that's needed to make path changes take effect - not a full log out and back in.
     
  15. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #15
    Normally you are right, but I have had instances were I have to do a full log out and back in again for changes to register. Normally that is when I am editing existing path entries rather than adding completely new ones though.
     
  16. Caezar thread starter macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #16
    Still no luck. I shut down my Mac, had a shower , brushed my teeth, went to bed, slept, woke up, turned my Mac back on, launched the terminal and went I type Python, it still launches 2.5.1.

    How did I install: downloaded an image from www.python.org and opened the package.
     
  17. MikhailT macrumors 601

    Joined:
    Nov 12, 2007
    #17
    Dude, just type python and press tab to see a list of all python binary files. it is most likely python3.1.

    The default will always remain 2.5.1 unless you update your config to point to 3.1 instead.
     
  18. Libripens macrumors newbie

    Joined:
    Jun 20, 2012
    #18
    Just Type "python3"

    I installed Python 3.2.3, and I was having the same problem. Finally, I typed "python3" in terminal and it worked. If just type "python" I get the previous version though.
     
  19. MorphingDragon macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #19
    Most linux distros use python3 as an alias, so if you're writing cross platform scripts/apps I would suggest python3.
     

Share This Page