I use python-mode.el instead of python.el for python work, and all of my customizations depend on it. However, periodically for some reason the python.el that ships with Emacs23 will magically get loaded and suddenly all of my configuration just goes out the window.

How can I prevent this? Right now, I have this code in my .emacs:

(if featurep 'python)
    (unload-feature 'python))

That seems to reduce the instances of this happening, but sometimes I'll open a python file -- in the same session! -- and it'll get the python.el python-mode instead of the python-mode.el version. And yet, the next buffer over still has the old mode.

This is quickly driving me bananas!

5 Answers 5


It all depends on how you've set up your .emacs.

By default, the function 'python-mode is associated with the package python.el. You need to change that with the following:

(autoload 'python-mode "python-mode" "Python Mode." t)

That assumes the python-mode package is already on your load-path. You'll also need to be sure that the above happens in your .emacs before anything causes the python.el to be loaded.

These other two lines are probably not needed, but don't hurt:

(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))

If that doesn't work, then we'll need more information.

Another alternative is to override the functions that are auto-loaded from python.el, which as of Emacs 23.1 are the following:

(defun run-python (&rest args) nil)
(defun python-mode (&rest args) nil)
(defun jython-mode (&rest args) nil)
(defun python-shell (&rest args) nil)

If you define those in your .emacs, then the autoloads that Emacs sets up will have no effect. You'll have to load python-mode.el manually (since the autoload for python-mode doesn't need to be run (because you defined that function)). Load the python-mode.el with:

(load "/path/to/python-mode.el")

Should it happen again, it signals a bug in python-mode.el too. Python-mode.el – that's my endeavour – should be designed in a way, python.el does not disturb, even if loaded.

In case, please make an entry at the bug-tracker.


You should be able to simply remove python.el (and perhaps the .elc? Is that still the extension for the compiled file)

  • The problem there is that the .el.gz file is part of the core Emacs distribution, over in non-user-space.
    – Chris R
    Feb 14, 2010 at 16:02

One nice thing is to inspect the file loading depedency via the load-history variable. Search for the cons (require . python) in it. This cons will be associated to a loaded file. This might help in order to understand the load depedencies and modify the load sequence of the different python modes.

To make sure you never load python.el and python.elc, get rid of it in emacs's installation files. And add this to your init file:

(autoload 'python-mode "python-mode")

But if you cannot do that because some other package depends on it, you can try to put the following in you init file. It loads python-mode.el after python.el and overrides its definitions:

(require 'python) (require 'python-mode)

I have experienced the same problem. Even though I had a proper (require 'python-mode) form in my init.el and no load requirement to python.el. In my case, python.el kept on being loaded after python-mode.el which overrode my settings. It was due to semantic/wisent/python.el which tries to load python.el.


the following link may also be relevant..


i use python-mode and despite the above advised code featuring in my .emacs, i still had to do things like..

M-x py-pdbtrack-toggle-stack-tracking  ; followed by..
M-x python-pdbtrack-toggle-stack-tracking

..to actually turn off a feature.

the culprit was the wisent-python.el python.el dependency which caused the re-loading of some common variable defs. i commented the (require 'python nil t) as i already manually define the include path that it (the code requiring this file) sets up anyway.

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.