18

I am trying to configure Python for my Emacs on Ubuntu, and I get the following error:

/usr/bin/env: python2: No such file or directory

Can someone help me with it? What can I do to resolve it?

plamut
  • 2,702
  • 9
  • 27
  • 35
murtaza52
  • 45,047
  • 27
  • 78
  • 118
  • I'm not sure why this was closed as 'off topic' since the question is about setting up the Python programming environment on Ubuntu and usually the first line of Python code on a UNIX system. Here's an explanation of what this line does and how to configure it for your system :http://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script – Will Feb 13 '14 at 17:10
  • By me the real display is `/usr/bin/env: « python2\r »: No such file or directory`. `/usr/bin/python2` is present. – Sandburg Sep 14 '18 at 14:31

3 Answers3

13

Try this command in terminal

sudo ln -s /usr/bin/python2.6 /usr/bin/python2

or

sudo apt-get install python2

ParaMeterz
  • 8,067
  • 1
  • 17
  • 21
  • I wish to go the symbolic link route as I did in the past, the machine recently had a clean reinstall to El Capitan. Even as sudo as follows `sudo ln -s /usr/bin/python2.7 /usr/bin/python2` I get the following 'ln: /usr/bin/python2: Operation not permitted' – R E N T B O Y Oct 12 '15 at 14:43
  • Problem solved. Using `ln -sf`allowed it to work. I'd checked it was't already linked using `ls -la | more` so its a bit of a mystery why `-f` worked even after doing a `man ln` and reading about it. Anyway problem solved. – R E N T B O Y Oct 12 '15 at 14:51
  • 3
    FWIW, this works on my version of El Capitan: sudo ln -s /usr/bin/python2.7 /usr/local/bin/python2 – Ariel Malka Sep 23 '16 at 23:42
9

Probably that's just true. The link /usr/bin/python2 -> (the real one) should be provided by your Python package, but that's obviously not the case, nor on any other location where it can be found via the $PATH.

You should put the said link in your path at the (an) appropriate place.

glglgl
  • 81,640
  • 11
  • 130
  • 202
  • 1
    But I have python in path, when I type "python" in my command line, it does open up the terminal. So how do I include in the past as recommended by you? – murtaza52 Jul 09 '12 at 08:11
  • That is strange. Normally, `env` should check the path. It also depends on under which circumstances the error occurs: do you have a different `$PATH` than normally? What says `which python2` in the shell? – glglgl Jul 09 '12 at 09:01
  • on 'which python2', I dont get any anything in the shell. How should I define it ? – murtaza52 Jul 09 '12 at 09:27
  • 4
    oh, stop. You type `python`, you said, not `python2`. Either change the script to call `python`instead of `python2`, or do a `ln -s /usr/bin/python /usr/local/bin/python2`. It is an ugly trick, however, and really should be done by the packet. But I cannot tell you why this isn't the case... – glglgl Jul 09 '12 at 10:24
  • 1
    thanks and appreciate your help – murtaza52 Jul 09 '12 at 14:22
2

On Ubuntu 12.04.

To find out what package owns the file:

$ apt-file -F find /usr/bin/python2
python-minimal: /usr/bin/python2

To find out what packages depend on the package:

$ apt-cache rdepends python-minimal
python-minimal
Reverse Depends:
  python2.7-minimal
 |livecd-rootfs
  python-minimal:i386
  python-support
  python2.7-minimal
  python
 |livecd-rootfs

It show that if you have python package then you should have python-minimal package then you should have /usr/bin/python2 file.

Check whether /usr/bin is in $PATH inside emacs. If it is and you can't run /usr/bin/python2 from a shell then you could reinstall python-minimal to restore /usr/bin/python2 file:

$ sudo apt-get --reinstall install python-minimal
jfs
  • 346,887
  • 152
  • 868
  • 1,518