The 3rd argument to call-process-region
is an executable file name, not a whole command, so you should call it like this:
(call-process-region
(point-min) (point-max) "python" nil nil nil
"/Users/myname/code/move_imports/moveimports.py")
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:
(shell-command-on-region
(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.
~
before your path, i.e.,~/Users/myname/code/move_imports/moveimports.py
moveimports.py
in Emacs, and check the value ofbuffer-file-name
withC-h v buffer-file-name
and use the path that it returns.(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?exec-path
does not include the directory for thepython
executable (and you have not used an absolute path for that in the shebang line).