Search code examples
pythonemacselpy

Setting up Emacs to run python using elpy


I recently downloaded Emacs 25.2 with the dependencies on Windows 10. I'm attempting to run python script using elpy. I created an init file including -

(require 'package)
(add-to-list 'package-archives
         '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(elpy-enable)

After failing, I also manually installed elpy - After running the first half of the init (above) ->

M-x package-refresh-contents RET
M-x package-install RET elpy RET
  1. It seems to have downloaded but I cannot access M-x elpy-config - Error message:

No such file or directory, python.

  1. Nor can I compile basic code -
print("Hello world")

Error message:

python HelloWorld.py 'python' is not recognized as an internal or external command, operable program or batch file.

Compilation exited abnormally with code 1

  1. When in the code it seems like none of the features elpy is supposed to have are working.

  2. I also cannot indent using tab in the script... I'm not sure if this is the same issue though.

I believe python is pre downloaded with emacs. Is this correct? Is there something I am missing in order to do this?

Thanks!

Edit: I realize having all of my init.el file may be necessary:

;; style
(menu-bar-mode 1)
(toggle-scroll-bar -1)
(tool-bar-mode 1)
(setq ring-bell-function 'ignore)
(customize-set-variable 'blink-cursor-mode nil)
(setq frame-title-format "")
(setq-default cursor-type 'vbar)

;; melpa
(require 'package)
(add-to-list 'package-archives
         '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))

(defvar myPackages
  '(monokai-theme
    elpy
    flycheck
    better-defaults
    powerline))

(mapc #'(lambda (package)
      (unless (package-installed-p package)
        (package-install package)))
      myPackages)

(require 'powerline)

(cd "C:/My Documents")
(setq
   backup-by-copying t      ; don't clobber symlinks
   backup-directory-alist
    '(("." . "~/.saves/"))    ; don't litter my fs tree
   delete-old-versions t
   kept-new-versions 6
   kept-old-versions 2
   version-control t)       ; use versioned backups

(setq inhibit-startup-message t)

(elpy-enable)
(when (require 'flycheck nil t)
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'flycheck-mode))

(powerline-default-theme)
(load-theme 'monokai t)
(set-background-color "#2f343f")
(set-cursor-color "#A6E22E")
(set-face-attribute 'fringe nil    
            :background "#2f343f")


Solution

  • I did not have python in my path of my environmental variables.

    In order to fix this:

    • Open windows search bar
    • search for environmental variables
    • Path > Edit... > New
    • Add the location of the python files

    Another way to do this is reopen the installer and be sure to select the box add to path when re installing it. You may need to uninstall python to do this second way.

    Good Luck!