-Bash: /Usr/Bin/Yum: /Usr/Bin/Python: Bad Interpreter: No Such File or Directory

-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

Don't modify the system python; too many things rely on it (like your package manager!). If you want to install a different version of Python, install it somewhere else (/usr/local, your home directory, etc).

If you actually deleted the python2.6 directory (e.g., /usr/lib/python2.6), you haven't just deleted python 2.6 -- you have deleted any additional python modules that were installed on your system, potentially breaking all sorts of things. There's not really a good way to recover from this situation.

If you were to restore the /usr/lib/python2.6 directory from another system you would at least be able to run yum again, although your system would still be fundamentally broken. Your best bet is to reinstall from scratch.

If you only deleted the python2.6 binary and left the library directory intact, you could simply restore /usr/bin/python2.6 and things would be relatively back to normal.

How to fix Bad interpreter error when using yum?

The first line of any bash, Perl, or Python script tells bash where to find the correct interpreter. For yum it is:

#!/usr/bin/python

You can tell where Python is actually installed by typing:

which python

The best way to fix this is to add a symbolic link. For example:

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

That way you don't have to fix it in every script.

/usr/bin/python: bad interpreter: No such file or directory after installing python 2.7

As suggested by @ForceBru, changing the scripts from /usr/bin/python to /usr/bin/python2 seems to work.

This is due to the fact that Ubuntu Python packages are always coming as python2 and python3, not python.

How to fix /usr/local/bin/virtualenv: /usr/bin/python: bad interpreter: No such file or directory?


bash: /usr/local/bin/virtualenv: /usr/bin/python: bad interpreter: No such file or directory

The error is in '/usr/local/bin/virtualenv' — it's first line (shebang) is #!/usr/bin/python and there is no such file at your system.

I believe the stream of events led to the situation is: you've installed virtualenv with pip (not apt) long ago and put /usr/local/bin at the front of your $PATH. Then you upgraded you system; the upgrade removed /usr/bin/python, now you have only /usr/bin/python3.

Now you have to decide which route you'd go: apt or pip. If you choose apt — remove /usr/local/bin/virtualenv.

If you choose pip: my advice is to uninstall as much as possible python packages installed with apt; reinstall virtualenv; that should be the only additional package installed with apt. For every project/task create a virtual environment and install packages with pip.

PS. Personal experience: I switched from apt way to pip a few years ago.

PPS. Avoid using sudo pip — do not clobber system installation. Either install into virtual environments or pip install --user.

Should I put #! (shebang) in Python scripts, and what form should it take?

The shebang line in any script determines the script's ability to be executed like a standalone executable without typing python beforehand in the terminal or when double clicking it in a file manager (when configured properly). It isn't necessary but generally put there so when someone sees the file opened in an editor, they immediately know what they're looking at. However, which shebang line you use is important.

Correct usage for (defaults to version 3.latest) Python 3 scripts is:

#!/usr/bin/env python3

Correct usage for (defaults to version 2.latest) Python 2 scripts is:

#!/usr/bin/env python2

The following should not be used (except for the rare case that you are writing code which is compatible with both Python 2.x and 3.x):

#!/usr/bin/env python

The reason for these recommendations, given in PEP 394, is that python can refer either to python2 or python3 on different systems.

Also, do not use:

#!/usr/local/bin/python

"python may be installed at /usr/bin/python or /bin/python in those
cases, the above #! will fail."

―"#!/usr/bin/env python" vs "#!/usr/local/bin/python"

PyCharm. /usr/bin/python^M: bad interpreter

Set line separator to Unix:

Unix



Related Topics



Leave a reply



Submit