How do I make Python 3.5 my default version on MacOS?

后端 未结 7 2296
迷失自我
迷失自我 2020-12-28 10:46

I have just installed Python 3.5.1 on my Mac (running the latest version of OSX). My system came with Python 2.7 installed. When I type IDLE at the Terminal pro

7条回答
  •  臣服心动
    2020-12-28 11:19

    It's good practice to have your MacOS Python environment set up properly from the beginning making sure that Homebrew installations take precedence over stock MacOS binaries. You want it in usr/local/bin not MacOS default usr/bin.

    .bash_profile

    # Ensure user-installed binaries take precedence
    export PATH=/usr/local/bin:$PATH
    # Load .bashrc if it exists
    test -f ~/.bashrc && source ~/.bashrc
    

    Can also create aliases for both.

    alias py2='python2.7'
    alias py3='python3.6'
    

    Source the file to ensure it takes effect for the current session

    source ~/.bash_profile
    

    Homebrew install and setup etc...

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
    brew doctor
    brew update
    brew upgrade --all
    brew cleanup
    

    Python3 install

    brew install python3
    

    Next

    pip3 install virtualenv
    

    Next

    pip3 install virtualenvwrapper
    

    When all is finished python3, pip3, virtualenv, and virtualenvwrapper.sh will all be in usr/local/bin.

    Result

    Every time I install anything or use commands like mkvirtualenv Python 3 is used by default.

提交回复
热议问题