This is a minimal pythonbrew utility for emacs. It does only the minimal things : computing the path to various python binaries, and setting exec-path and PATH accordingly.
This is a total ripp-off from perlbrew-mini.el by Damien Krotkine (https://github.com/dams/perlbrew-mini.el)
In your .emacs :
(require 'pythonbrew-mini) (pythonbrew-mini-use-latest)
By default this will try to find pythonbrew pythons from $HOME/.pythonbrew/pythons/. It will then try to use the latest python found in that directory. You can override the various options below:
To override the pythonbrew directory:
;; by default pythonbrew-mini-set-pythons is set to $HOME/.pythonbrew/pythons/ (pythonbrew-mini-set-pythons-dir "/home/username/path/to/pythonbrew/pythons/")
To override which pythonbrew python version to use:
;; by default it will use the latest python (alphanumeric comparison on the file name) (pythonbrew-mini-use "Python-2.7.1")
Once loaded, pythonbrew-mini provides these functions:
pythonbrew-mini-get-current-python-path ;; returns the current python path pythonbrew-mini-get-current-version ;; returns the current python version in use
See below for a real life example
This is an example to use flymake with pythonbrew. This method will make flymake create its temporary file in the same directory than the Python source file it's examinating.
Warning, for this to work you need to install Project::Libs inside the pythonbrew you wish to use.
(require 'pythonbrew-mini) (pythonbrew-mini-use "python-5.12.2") (require 'flymake) (when (load "flymake" t) (defun flymake-pylint-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "pep8" (list "--repeat" local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pylint-init))) (add-hook 'python-mode-hook '(lambda () (setq python-indent 4) (setq fill-column 79) (flymake-mode)))