Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

macos - Unable to Run Python 3 After Homebrew Installation

After installing Homebrew using the script on their homepage and checking if everything was alright with brew doctor, I issued brew install python3 in order to install Python 3 on my Mac.

Everything seemed fine until I tried running python3 --version; I ended up getting:

-bash: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3: No such file or directory

I checked in the file directory to see what was going on and indeed, I didn't see any files pertaining to Python in my framework folder. It also looks like Python 2.7 isn't on my Mac either.

This is what I got after installing Python 3:

Summary ?? /usr/local/Cellar/python3/3.5.1: 3,438 files, 51.5M

edit_2: maybe this has something to do that there is no Python framework? I just read this off the Python website:

The Apple-provided build of Python is installed in /System/Library/Frameworks/Python.framework and /usr/bin/python, respectively. You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software. Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think I detected what the problem is.

I guess that, at a certain moment, you had installed python from the official site instead of via Homebrew. In my case, I installed it 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
  1. 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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...