Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 318
vcyf56rtrfc Avatar asked Mar 15 '16 03:03

vcyf56rtrfc


People also ask

How do I enable Python 3?

Python 3 can be installed using the official Python 3 installer. Go to the Python Releases for Mac OS X page and download the latest stable release macOS 64-bit/32-bit installer. After the download is complete, run the installer and click through the setup steps leaving all the pre-selected installation defaults.


3 Answers

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 :)

like image 120
Román Cárdenas Avatar answered Nov 15 '22 08:11

Román Cárdenas


I had the same issue. I learned how to fix it for good:

  1. Open "Applications" in Mac Finder and drag Python to the trash bin.
  2. Empty the trash bin

If you have an error as above, then an official Python installation has been performed (as others have mentioned) via e.g. Python.org. This creates some kind of alias for the python or python3 commands outside a Bash alias. So while the command where python3 may point to /usr/local/bin/python3, python3 will still try to call /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.

Note:

  • the MacOS system Python is /usr/bin/python
  • Homebrew Python(s) will be located in /usr/local/bin/
  • Pythons installed as an Apple application live in /Library/Frameworks/Python.framework/
like image 45
statueofmike Avatar answered Nov 15 '22 06:11

statueofmike


Okay, this is what I gathered:

  • Don't delete the Python framework!
  • If it's deleted, then python3 --version won't work
  • Just install Python from the Python website
  • The framework will return and python3 --version will work
like image 20
vcyf56rtrfc Avatar answered Nov 15 '22 06:11

vcyf56rtrfc