I have the following snippet:

(call-process-region (point-min) (point-max) 
   "python /Users/myname/code/move_imports/moveimports.py")

Incredibly, it tells me that it cannot find the file, even though it exists in the very same location given. Same happens with

(call-process-region (point-min) (point-max) 
   "/Users/myname/code/move_imports/moveimports.py"))) ; Using shebang in python file

How can I fix this problem and run the executable by using the full path?

edit: The error I am getting is Searching for program: no such file or directory.

  • Try adding ~ before your path, i.e., ~/Users/myname/code/move_imports/moveimports.py
    – elethan
    Commented Jan 12, 2016 at 22:17
  • Alternatively, visit your python script moveimports.py in Emacs, and check the value of buffer-file-name with C-h v buffer-file-name and use the path that it returns.
    – elethan
    Commented Jan 12, 2016 at 22:44
  • 3
    1st call should be (call-process-region (point-min) (point-max) "python" nil nil nil "/Users/myname/code/move_imports/moveimports.py"), can't say why the 2nd should fail, unless the shebang is wrong?
    – npostavs
    Commented Jan 12, 2016 at 23:01
  • Does your command work when you run it from a shell? Which file can't it find? Show us the exact error you're getting. There is very little information to go on in this question...
    – phils
    Commented Jan 12, 2016 at 23:56
  • Oh, the subject line has the error. That sounds to me as if the Emacs exec-path does not include the directory for the python executable (and you have not used an absolute path for that in the shebang line).
    – phils
    Commented Jan 13, 2016 at 3:39

1 Answer 1


The 3rd argument to call-process-region is an executable file name, not a whole command, so you should call it like this:

 (point-min) (point-max) "python" nil nil nil

This looks for an exectutable named python that should be located in one of the directories listed in exec-path (you could provide the full path to python instead).

The original call would attempt to execute a file called moveimports.py under a subdirectory named python /Users/myname/code/move_imports/.

You may find it easier to use shell-command-on-region which would work with your first form:

 (point-min) (point-max) 
 "python /Users/myname/code/move_imports/moveimports.py")

You do have to watch out for spaces in file names and other shell meta-characters in this case though. Also note that the shell uses the environment variable PATH which usually (but not necessarily) contains the same list (encoded to a : separated string) as exec-path (especially Mac users should consider using exec-path-from-shell).

I believe the second form

(call-process-region (point-min) (point-max) 
   "/Users/myname/code/move_imports/moveimports.py"))) ; Using shebang in python file

should work unless "/Users/myname/code/move_imports/moveimports.py" is not marked executable, or its shebang is incorrect.

  • I read that an interactive function like shell-command-on-region should preferably avoided in elisp code (no reason was given?) Commented Jan 13, 2016 at 19:38
  • 1
    @TheUnfunCat: no, certain interactive functions should be avoided in elisp code (usually because they cause visible UI effects), but many (most?) interactive functions can be used non-interactively as well. You may want to avoid shell-command-on-region because of the complications using a shell brings (e.g. meta-characters in file names).
    – npostavs
    Commented Jan 13, 2016 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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