16

Python is broken somehow after running a script that rewrites files. I get the error anytime I use it:

$ python
-bash: /usr/local/bin/python: No such file or directory

I did brew doctor:

$ brew unlink python && brew link python

Yesterday I tried to fix it by reinstalling:

$ brew update
$ brew install python
$ brew upgrade python

Based on what I found it seems like I need to symlink it but I don't want to make it worse and lose the entire OS.

$ which python
/usr/bin/python

How can I fix this Python?

halfer
  • 19,824
  • 17
  • 99
  • 186
codyc4321
  • 9,014
  • 22
  • 92
  • 165
  • Looks like `/usr/local/bin` is earlier in your path and there is a `python` is `/usr/local/bin` that is a softlink to something that doesn't exist. `ls -l /usr/local/bin/python` and see where it is pointing. – AChampion Sep 12 '17 at 14:58
  • Don't use `which` -- it isn't part of the shell, and doesn't know about aliases, shell functions, the structure used to cache PATH lookup results, or any number of other oddnesses. Instead, use `type python` to figure out what's going on. – Charles Duffy Sep 12 '17 at 15:04
  • @AChampion, if `/usr/local/bin` were earlier in the PATH, `which` would have identified the copy there. More likely we have an alias or function. – Charles Duffy Sep 12 '17 at 15:08
  • @codyc4321, ...if you're still interested in a proper fix, could you please [edit] the question to provide output of the command `type python` when the system is in a state where the error occurs? – Charles Duffy Sep 12 '17 at 16:06

2 Answers2

31

Something seems to go haywire with Homebrew 1.7.2 and MacOS 10.13.6.

Even after removing all python versions and reinstalling, python --version simply won't work.

Most have probably already tried these steps...

brew uninstall --ignore-dependencies python
brew uninstall --ignore-dependencies python2
brew uninstall --ignore-dependencies python3
brew install python
brew unlink python && brew link python
brew unlink python3 && brew link python3

At the end what worked for me was...

sudo ln -s /usr/local/bin/python3 /usr/local/bin/python

And then again for pip...

sudo ln -s /usr/local/bin/pip3 /usr/local/bin/pip
tresf
  • 7,103
  • 6
  • 40
  • 101
2

I've got no idea what happened here, but I tried reinstalling yesterday...reinstalling this way (seemingly what I already did) today worked:

How to fix broken python 2.7.11 after OSx updates

codyc4321
  • 9,014
  • 22
  • 92
  • 165
  • If this is what actually solved your problem, why isn't it the accepted answer? – Charles Duffy Sep 12 '17 at 16:07
  • It has a 2 day block, the guy tried, and there's no reminder system to tell you to accept the answers – codyc4321 Sep 12 '17 at 16:07
  • He tried, but marking something accepted means it's the first thing other people are going to look at if they have the same problem. Rewarding effort as opposed to accuracy might feel like the "nice" thing to do, but it doesn't help other people with the same problem -- which is the whole point of curating a Q&A knowledgebase. – Charles Duffy Sep 12 '17 at 16:09
  • Everytime someone links an article "explaining" SO design decisions I wonder if the person who wrote it ever used this beast. Why isn't there a serious competitor?!?! – codyc4321 Sep 12 '17 at 20:10
  • If they're not gonna let you pick an answer as correct within 48 hours, just have a reminder when I log in for the questions to pick answers for. This site is a great concept but a sloppy mess to use – codyc4321 Sep 12 '17 at 20:11
  • And it won't let the guy delete his answer? Cmon – codyc4321 Sep 12 '17 at 20:11