0

I am very new to emacs so it would be a big help if answers came with a lot of detail.

I've tried to get my M-x shell to run python 3 but can't. I've tried:

(setq python-shell-interpreter 
      "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6")

and also adding this location to ~/.emacs but neither have worked. I have python 3.6 installed and running in terminal but can't get it running in the M-x shell. I'm using a mac.

  • M-x shell is for running a shell inside an emacs window. Are you saying that in that shell, when you run python you get python2? An error? What error? – NickD Jan 8 '18 at 13:07
  • Yeah sorry. When I run python in that shell it uses python 2 – L Doe Jan 8 '18 at 13:14
  • Maybe setting PATH as in this answer would help? – npostavs Jan 8 '18 at 14:13
  • Are you trying to get an interactive python REPL? Or just want to run a python script? Starting a shell from emacs and running python is a good way to do the latter, but Emacs has better ways to do the former – purple_arrows Feb 8 '18 at 1:03
  • Since you've got python-shell-interpreter set, you can say M-x run-python to get to an interactive repl directly. Down that rabbit hole you'll also learn how to send code directly from a python buffer to the repl, and other stuff that's useful for development – purple_arrows Feb 8 '18 at 1:06
1

M-x shell gives you an emacs buffer that mostly behaves as a regular shell terminal. That means that when you issue a command, like find, grep or python, it searches through your system path and runs the first program it finds that matches the name you used. The variable python-shell-interpreter has nothing to do with this.

Which means, on your system, the executable for python is pointing to python 2, not python 3. You'll have to fix this outside of emacs. Or you can explicitly set it within M-x shell if you want to make this a temporary change:

alias python=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

You may prefer to directly alter the path.

You could also include code to modify your path, or set up an alias for python, in .emacs.d/init_bash.sh, which is applied every time you run M-x shell.

0

You can also run your script using python3 script.py too.

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.