How can I prevent the python.el that ships with Emacs 23 from EVER loading?

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!


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)