Unable to Run Python 3 After Homebrew Installation

前端 未结 4 1459
终归单人心
终归单人心 2020-12-18 05:32

After installing Homebrew using the script on their homepage and checking if everything was alright with brew doctor, I issued brew install python3

4条回答
  •  死守一世寂寞
    2020-12-18 06:00

    I think I detected which is the problem.

    I guess that, in a certain moment, you had installed python from the official site instead of via Homebrew. In my case, I installed via the official website Python 3.6.4. A few months later, I wanted to upgrade it, and noticed that it was very complex. So, I decided to move to Homebrew. Open a terminal window and let's try to fix this: 1. First, let's uninstall previous Python versions:

        sudo rm -rf /Library/Frameworks/Python.framework
        sudo rm -rf /usr/local/bin/python3
    

    2. Then, remove the previous frameworks from the $PATHvariable:

        nano ~/.bash_profile
    

    You will see something like that:

        # Setting PATH for Python 2.7
        # The original version is saved in .bash_profile.pysave
        PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
        export PATH
    
        # Setting PATH for Python 3.6
        # The original version is saved in .bash_profile.pysave
        PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
        export PATH`
    

    This is the problem: These paths don't exist. Comment the $PATH editions (or erase them):

        # Setting PATH for Python 2.7
        # The original version is saved in .bash_profile.pysave
        # PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
        # export PATH
    
        # Setting PATH for Python 3.6
        # The original version is saved in .bash_profile.pysave
        # PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
        # export PATH
    

    3. Restart the computer and install via Homebrew Python 2 and 3:

        brew update
        brew install python
        brew install python3
    

    This worked for me. Now, if type python3 --version I get Python 3.7.0, and everything works fine :)

提交回复
热议问题