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__':"                   
Donbeo
  • 111
  • 3
  • 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 01:32
  • how can I check what it is bounded to? – Donbeo Jan 20 '18 at 02: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 02:56
  • @sshaw I have added some details – Donbeo Jan 22 '18 at 11:16
  • They're bound to the same function. If you run `emacs -Q` on Ubuntu and press `C-c C-c` do you still get the desired behavior? You may just want to add `run-python` to your init file. – sshaw Jan 23 '18 at 02:12
  • running emacs with `-Q` i get the same behavior but the shell is with standard python rather than ipython. Where and how should I add `run-python` to my init file? Can you post an example `init` file? – Donbeo Jan 23 '18 at 10:28
  • 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 01:32
  • ok it seems to work on one laptop. If it works also on the other one I'll accept the solution – Donbeo Jan 25 '18 at 16:23

0 Answers0