Python@2 Problem


(Josh Jay) #1

I get this error all over the place.

/usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

Can somebody help? I was posting on a Github topic for help, but I didn’t get any where.


(Wu Yongwei) #2

I got this problem too (quite a few tools installed by pip). Uninstall the packages that had this problem, and then reinstall them.

This was caused by the python-to-python@2 change.


(Eduard Rozenberg) #3

Homebrew recently changed default python from python(v2) to python(v3).

If you’ve recently done a brew upgrade, this means you now have python3 installed instead of python2. To confirm check $ brew info python and $ ls -al /usr/local/bin/python*

You have a couple of options.

Option 1: Install python2 and keep using pip2 packages and python2 code:

  • $ brew install python@2
  • $ pip2 install --upgrade <somepackage> for any pip packages you need
    Note: look in older python version dirs /usr/local/lib/python2.X/site-packages/ if you can’t remember which pip packages you’ve used in the past.

Option 2: Use python3 and install necessary packages with pip3:

  • Modify your own code to run under python3
    Note: this may be a small or large undertaking depending on how much code
  • $ pip3 install --upgrade <somepackage> for any pip packages you need
    Note: take a look at /usr/local/lib/python2.X/site-packages/ and install those same packages for python3 using pip3. Not all python2 packages are available for python3, but many(most?) are.

(Josh Jay) #4

Thanks for the suggestions. I was aware that Homebrew switched python to python3. I was starting from a clean install, using Bundle. It looks like I already have the most up to date python packages.


(Josh Jay) #5

I’ve removed python@2 and python completely from my system and I still get this error.


(Eduard Rozenberg) #6

Some code you’re running, or modules that code is loading, is trying to run under under that python2 interpreter path. You’ll have to figure out which code is doing this. You provided no information about commands you’re running so nobody will be able to suggest anything further.


(Josh Jay) #7

I’m getting this error with the saws command.

I tried this
ln -s /usr/local/bin/python /usr/local/opt/python/bin/python2.7
and it seemed to help.

Now the question is - what python version should I expect when I type python? Obviously python3 is python 3. Hope this provides more context!


(Eduard Rozenberg) #8

You installed saws and other pip stuff for homebrew python2. Then you uninstalled homebrew python2. cat /usr/local/bin/saws to see the the problem. Don’t modify saws though that’s not the right fix.

This is not a good idea: ln -s /usr/local/bin/python /usr/local/opt/python/bin/python2.7

You’ll have to follow option 1 or option 2 and reinstall saws with either pip2 or pip3 to fix your saws setup. If you still get stuck it’ll help to read about pip commands, understand pip2 vs pip3, and also be aware of ‘shebangs’. It’s an easy fix and with python etc. it only gets harder from here - good luck.


(Josh Jay) #9

I’m all for using the easy way, hell I’m fine with wiping my brew installs of python if I could figure out how to properly reset everything at start fresh. I will delete the symlink. I’m not opposed to following the advice, I’m just fairly certain that something is corrupted somewhere. How can I start fresh?


(Josh Jay) #10
cat /usr/local/bin/saws
#!/usr/local/opt/python@2/bin/python2.7

# -*- coding: utf-8 -*-
import re
import sys

from saws.main import cli

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(cli())`

(Josh Jay) #11

Also saws was installed with pip - I don’t think it works with pip3 after I installed python@2 from brew.


(Eduard Rozenberg) #12

brew install python@2
pip2 install --upgrade saws


(Josh Jay) #13

Thanks, I’ll give that a try. I’m outside of a venv right now, do I got a permission denied error. Is this okay to run with sudo or should i pass the --user parameter?


(Josh Jay) #14

Looks like I should be using pip2 instead of pip then?


(Josh Jay) #15

I’m having some problems with my Venvs now. For some reason, the new venv folders I create are fine for a while and then the bin/ folder is missing the activate scripts the next day. Any ideas?