0

I am trying to get python-mode.el and ipython to work with emacs. I downloaded the newest GNU emacs and python-mode.el, put the files into .emacs.d/python-mode.el-6.1.2 and wrote the following in the emacs init file:

; Python-mode
(setq py-install-directory "~/.emacs.d/python-mode.el-6.1.2")
(add-to-list 'load-path "~/.emacs.d/python-mode.el-6.1.2")
(require 'python-mode)

From here it should be able to recognize python-mode, but I cannot get it to. When I open a .py file, the mode is Python (python.el), not Py (python-mode). What am I doing wrong? Next I would like to be able to execute code from emacs via ipython - I figured just to follow the official site: http://ipython.org/ipython-doc/stable/config/editors.html..

Any help on python-mode and advice on ipython compatibility? I got python and ipython up and running, but I'm all new to emacs.

Thanks in advance!

elemakil
  • 3,681
  • 28
  • 53
  • 1
    Here's something that can help with `ipython`: http://stackoverflow.com/questions/19495889/how-to-quickly-create-a-ipython-shell-in-emacs/19496162#19496162 –  Oct 27 '13 at 16:12
  • 1
    If you're all new to emacs I'd suggest reading this wiki http://wikemacs.org/index.php/Python and installing packages with… `packages`: `M-x list-packages` in emacs 24 and look for python-mode and ipython (and read the instructions). Hope this helps. – Ehvince Oct 28 '13 at 17:15

1 Answers1

2

You also need to tell emacs which mode to use when opening .py files

(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))
elemakil
  • 3,681
  • 28
  • 53
tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • Still not using py mode. Getting the following error: Warning (initialization): An error occurred while loading `/Users/tazz_dk/.emacs': error: The command named 'bzr' can not be found with `executable-find' To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the `--debug-init' option to view a complete error backtrace. – Mathias Jørgensen Oct 27 '13 at 18:18
  • @MathiasJørgensen Assume you have some code calling the DVC system bazaar. There is a way to get python-mode.el via bazaar, but it doesn't affect running it, so you don't need bazaar. – Andreas Röhler Oct 27 '13 at 18:30
  • @MathiasJørgensen I don't think that is not coming from `python-mode.el` – tacaswell Oct 27 '13 at 18:33
  • Thanks for the answers. The add-to-list commands does not seem to work though. Must have done something wrong in installing python-mode? What is the command to manually activate python-mode? I tried M-x python-mode among others, but it says that it cannot "guess python-indent-offset" and just activates the python.el mode. – Mathias Jørgensen Oct 27 '13 at 19:10
  • That sounds like you have a file with mixed tabs and spaces. I would start emacs with out reading your `.emacs` file (there is a command line switch) and the selectively execute the commands related to python-mode and see if it works. – tacaswell Oct 27 '13 at 19:17
  • @MathiasJørgensen Let's forget setting up for a moment, just have the experience: start emacs -Q from directory where python-mode.el is in. Open python-mode.el and M-x eval-current-buffer RET. Than open a --maybe empty-- file with ending ".py". You should see "Py" appear in mode-line. – Andreas Röhler Oct 27 '13 at 19:47
  • If you have mixed tabs and spaces, try calling `M-x untabify`. You can use `M-x ielm` (Iteractive Emacs Lisp M…) to execute emacs commands one by one. – Ehvince Oct 28 '13 at 17:18