1

I have always used emacs with python. I generally run my code on the ipython interpreter using C-c C-c.

This is my ~/.emacs.d/init.el in ubuntu where everything works fine.

(setq python-shell-interpreter "ipython"                                                                                                                                                                    
      python-shell-interpreter-args "--simple-prompt -i")                                                                                                                                                   
(custom-set-variables                                                                                                                                                                                       
 ;; custom-set-variables was added by Custom.                                                                                                                                                               
 ;; If you edit it by hand, you could mess it up, so be careful.                                                                                                                                            
 ;; Your init file should contain only one such instance.                                                                                                                                                   
 ;; If there is more than one, they won't work right.                                                                                                                                                       
 '(ansi-color-names-vector ["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#ad7fa8" "#8cc4ff" "#eeeeec"])                                                                                               
 '(custom-enabled-themes (quote (wombat)))                                                                                                                                                                  
 '(inhibit-startup-screen t))                                                                                                                                                                               
(custom-set-faces                                                                                                                                                                                           
 ;; custom-set-faces was added by Custom.                                                                                                                                                                   
 ;; If you edit it by hand, you could mess it up, so be careful.                                                                                                                                            
 ;; Your init file should contain only one such instance.                                                                                                                                                   
 ;; If there is more than one, they won't work right.                                                                                                                                                       
 )                                                                                                                                                                                                          
(put 'erase-buffer 'disabled nil)                                                                                                                                                                           



(add-hook 'python-mode-hook                                                                                                                                                                                 
      (lambda ()                                                                                                                                                                                            
        (setq indent-tabs-mode t)                                                                                                                                                                           
        (setq tab-width 4)                                                                                                                                                                                  
        (setq python-indent 4)))                                                                                                                                                                            

On the other hand on my mac I receive the following message when I try to run python interactively with C-c C-c

Start a Python process first with ‘M-x run-python’ or ‘C-c C-p’.

How can I get the same behaviour that I have on ubuntu ? Is this due to the emacs version?

EDIT Additional information:

This is the description of the C-c C-c command on ubuntu.

C-c C-c runs the command python-shell-send-buffer, which is an                                                                                                                                                     
interactive compiled Lisp function.                                                                                                                                                                                

It is bound to C-c C-c, <menu-bar> <Python> <Eval buffer>.                                                                                                                                                         

(python-shell-send-buffer &optional ARG)                                                                                                                                                                           

Send the entire buffer to inferior Python process.                                                                                                                                                                 
With prefix ARG allow execution of code inside blocks delimited                                                                                                                                                    
by "if __name__== '__main__':"                   
  • What's function is C-c C-c bound to in Ubuntu? On my OS X emacs it's bound to python-shell-send-buffer which, as you see, wants a running process to work. – sshaw Jan 19 '18 at 1:32
  • how can I check what it is bounded to? – Donbeo Jan 20 '18 at 2:44
  • From the buffer that you're typing C-c C-c into type: C-h k, this will output a message in the minibuffer to "Describe key". Then press C-c C-c. This will open a buffer describing the function bound to that key sequence. – sshaw Jan 20 '18 at 2:56
  • @sshaw I have added some details – Donbeo Jan 22 '18 at 11:16
  • 1
    Add (run-python) after setting the 2 python-shell-* variables. But C-c C-c only sends the buffer (or portion of) to the python repl (sounds like that's okay and what you used to do, but not 100% clear). You still need to open it via C-c C-z which, if you don't add (run-python), will prompt you for a command to start. – sshaw Jan 25 '18 at 1:32

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.