I put the following in my .emacs file to make sure that the "run-python" variable maps to the right path:

(setq python-shell-interpreter "C:\\Users\\xxxx\\python.exe")

When I restart emacs and do M-x run-python; it I get the following error:

apply: Searching for program: no such file or directory, c\:/Users/xxxx/python.exe

I don't understand why emacs puts "c:/" instead of "c:\" and I assume that is why it cannot find the python's interpreter's path. Am I missing something?

UPDATE: The following works: C-u M-x run-python RET "python" -i

Make sure you don't put 'python'; and actually use quotation marks like ".

  • I suspect this is Emacs bug #20744
    – npostavs
    Sep 16 '16 at 16:24
  • @npostavs: Looks like it. Please post that as an answer.
    – Drew
    Sep 16 '16 at 16:40
  • @R Is your Emacs native w32, or cygwin (post output of M-x emacs-version)? Are you using some kind of bash-like shell instead of the default cmd.exe (post output of M-: (w32-shell-name))?
    – npostavs
    Sep 16 '16 at 21:56
  • 1st one: GNU Emacs 24.5.1 (i686-pc-mingw32) of 2015-04-11 on LEG570; 2nd one: "bash" Sep 19 '16 at 13:12

No, that is not the reason. (And Emacs apparently did not put c:/.)

And the problem is not the use of setq instead of Customize (though the latter is generally advisable). If you are using the vanilla library python.el then you'll see this in the file header:

;; Running IPython on Windows needs more tweaking.  The way you should
;; set `python-shell-interpreter' and `python-shell-interpreter-args'
;; is as follows (of course you need to modify the paths according to
;; your system):

;; (setq python-shell-interpreter "C:\\Python27\\python.exe"
;;       python-shell-interpreter-args
;;       "-i C:\\Python27\\Scripts\\ipython-script.py")

The error message you see says c\:. It does not say c:\ (and it does not say, as you suggested, c:/.

Are you sure that you have c:\ and not c\: in your init file? The colon (:) needs to come before the backslash (\) or the slash (/).

Update: It looks like the comment from @npostavs points to the problem: it's a bug in the python.el code. My "answer" speaks to the reason you gave and the reason that @choroba gave - neither is the cause of your problem.

And I guessed that either you mistyped c\: or the error message mistakenly really wrote that (instead of c:\).

  • I'm running elpy. I'm copying the .emacs and error message from Messages buffer below: Sep 16 '16 at 17:43
  • (setq python-shell-interpreter "C:\Users\xxxx\AppData\Local\Continuum\Anaconda2\python") Sep 16 '16 at 17:43
  • apply: Searching for program: no such file or directory, c\:/Users/xxxx/AppData/Local/Continuum/Anaconda2/python.exe Sep 16 '16 at 17:43
  • I tried the extended setq you mentioned above, still the same error. Sep 16 '16 at 17:44
  • See @npostavs's comment. That is the likely answer: this is a bug. My point in citing that file commentary text was to show that the answer from @choroba is incorrect about not using setq. The library itself says you can use setq.
    – Drew
    Sep 16 '16 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.