After installing Homebrew using the script on their homepage and checking if everything was alright with brew doctor
, I issued brew install python3
Okay, this is what I gathered:
python3 --version
won't workpython3 --version
will workI had the same issue. I learned how to fix it for good:
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:
/usr/bin/python
/usr/local/bin/
/Library/Frameworks/Python.framework/
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 $PATH
variable:
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 :)
This error:
-bash: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3: No such file or directory
suggests a remnant of some previous (attempt at an) installation of Python 3 using a different way (not Homebrew).
(I think this is actually where the Python installation from www.python.org goes. I wouldn't know though, as I've either never tried that package, but only installed the www.python.org version from source. This would suggest, though, that you already had an attempt at installing Python 3.5, something failed, and you're now trying Homebrew instead.)
I'd suggest moving (renaming) this out of the way, so your system doesn't pick it up. Something like
mv /Library/Frameworks/Python.framework/Versions/3.5 /Library/Frameworks/Python.framework/Versions/3.5-aside
(if there other versions of Python 3 in that directory, you may want to do the same for those.)
Also check that python3
isn't an alias. Commands such as
which python3
type python3
alias python3
will reveal that.
With the interfering Python 3 out of the way, try re-installing Python 3 through homebrew again. You may have to do an uninstall + reinstall.
Read carefully any homebrew messages once the installation is done, in particular if it mentions something about linking files: you may need to run something like brew link python3
.