jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.89k stars 259 forks source link

Windows emacs opens python graphs in "Paint" #1973

Open pauljohn32 opened 2 years ago

pauljohn32 commented 2 years ago

Steps to reproduce

In Python or Ipython shell, the TK graphics backend is found and used. Within Emacs/elpy, the graphic backend is Windows Paint.

In Windows, with Emacs 26.3 and Elpy 20201115.1811

import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots()
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)',
       title='About as simple as it gets, folks')
ax.grid()
plt.show()

My configuration

OS

Windows 10

Result of (elpy-config)

Elpy Configuration

Emacs.............: 26.3
Elpy..............: 1.35.0
Virtualenv........: venv-ita (c:/Users/A1146108/venv-ita/)
Interactive Python: jupyter 4.7.1 (c:/Users/A1146108/venv-ita/Scripts/jupyter.exe)
RPC virtualenv....: rpc-venv (c:/Users/A1146108/.emacs.d/elpy/rpc-venv)
 Python...........: c:/Users/A1146108/AppData/Local/Programs/Python/Launcher/py.exe 3.8.10 (c:/Users/A1146108/AppData/Local/Programs/Python/Launcher/py.exe)
 Jedi.............: Not found (0.18.1 available)
 Rope.............: Not found (1.0.0 available)
 Autopep8.........: Not found (1.6.0 available)
 Yapf.............: Not found (0.32.0 available)
 Black............: Not found (22.3.0 available)
Syntax checker....: Not found (flake8)

Warnings

The Jedi package is not currently installed. This package is needed
for code completion, code navigation and access to documentation.

[Install jedi]

No autoformatting package is currently installed. At least one is
needed (Autopep8, Yapf or Black) to perform autoformatting (`C-c C-r
f` in a python buffer).

[Install autopep8]
[Install yapf]
[Install black]

The configured syntax checker (flake8) could not be found. Elpy uses
this program to provide syntax checks of your code. You can either
install it, or select another one using `elpy-syntax-check-command`.

[Install flake8]

Options

`Raised' text indicates buttons; type RET or click mouse-1 on a button
to invoke its action.  Invoke [+] to expand a group, and [-] to
collapse an expanded group.  Invoke the [Group], [Face], and [Option]
buttons below to edit that item in another window.

Elpy configuration in my init.el

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (when no-ssl
    (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
  ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  (when (< emacs-major-version 24)
    ;; For important compatibility libraries like cl-lib
    (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
;; for stable packages, use this instead
;;add-to-list 'package-archives
;;             '("melpa-stable" . "https://stable.melpa.org/packages/") t)

(package-initialize)

;; tell emacs to use custom.el to write in, don't edit this file
;; https://www.reddit.com/r/emacs/comments/53zpv9/how_do_i_get_emacs_to_stop_adding_custom_fields/   
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)

(load "~/.emacs.d/pj-python-config.el")
(load "~/.emacs.d/pj-ess-config.el")
(load "~/.emacs.d/pj-org-config.el")

;; WSL adjustment
(setq ring-bell-function 'ignore)

;; Section II. Keyboard and mouse customization
(setq column-number-mode t)

;; Mouse and cursor in the usual Mac/Windows way
(delete-selection-mode t)
;; http://stackoverflow.com/questions/13036155/how-to-to-combine-emacs-primary-clipboard-copy-and-paste-behavior-on-ms-windows
(setq select-active-regions t)
;; Trying to make mouse middle-click only paste from primary
;; X11 selection, not clipboard and kill ring:
;;(global-set-key [mouse-2] 'mouse-yank-primary)
;; highlight does not alter Kill ring:
(setq mouse-drag-copy-region nil)
;; windows style binding C-x, C-v, C-c, C-z:
(cua-mode t)
;; Don't tabify after rectangle commands:
(setq cua-auto-tabify-rectangles nil) 
;; https://www.emacswiki.org/emacs/CuaMode
(transient-mark-mode 1) ;; No region when it is not highlighted
;; Wow, here's a horrible feature, the region stays highlighted. 
;;(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour

;; ;; Section III. Programming conveniences:
;; ;; light-up matching parens:
(show-paren-mode t)
;; ;; turn on syntax highlighting:
(global-font-lock-mode t)

(setq-default indent-tabs-mode nil)
(setq default-tab-width 4)
(setq default-buffer-file-coding-system 'utf-8-unix)

;; ;; Auto fill is TRUE in text modes:
;; (setq text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))

;; ;; Section V. Frames oriented Emacs
;; ;; Discourage Emacs from horizontal splitting:
;; ;; http://www.gnu.org/software/emacs/elisp/html_node/Choosing-Window.html
(setq split-window-preferred-function nil)
;; ;; (setq pop-up-windows nil)

;; ;; Make files opened from the menu bar appear in their own
;; ;; frames. Adapted from Emacs menu-bar.el
(defun menu-find-existing ()
  "Edit the existing file FILENAME."
  (interactive)
  (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog)
                              (x-uses-old-gtk-dialog))))
         (filename (car (find-file-read-args "Find file: " mustmatch))))
    (if mustmatch
        (find-file-other-frame filename)
      (find-file filename))))
(define-key menu-bar-file-menu [new-file]
  '(menu-item "Open/Create" find-file-other-frame
              :enable (menu-bar-non-minibuffer-window-p)
              :help "Create a new file"))
(define-key menu-bar-file-menu [open-file]
  '(menu-item ,(purecopy "Open File...") menu-find-existing
              :enable (menu-bar-non-minibuffer-window-p)
              :help ,(purecopy "Read an existing file into an Emacs buffer")))

;; Section VI: Miscellaneous convenience
;; https://www.emacswiki.org/emacs/SmoothScrolling#toc1
;; scroll one line at a time (less "jumpy" than defaults)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
(setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
(setq scroll-step 1) ;; keyboard scroll one line at a time

;; Remove Emacs "splash screen" http://fuhm.livejournal.com/
(defadvice command-line-normalize-file-name
    (before kill-stupid-startup-screen activate)
  (setq inhibit-startup-screen t))
(setq inhibit-splash-screen t)

;; Show file name in title bar
;; http://www.thetechrepo.com/main-articles/549
(setq frame-title-format "%b - Emacs")

;; Make Emacs scroll smoothly with down arrow key.
;; faq 5.45 http://www.gnu.org/s/emacs/emacs-faq.html#Modifying-pull_002ddown-menus
;;(setq scroll-conservatively most-positive-fixnum)

;; adjust the size of the frames, uncomment this, adjust values
(setq default-frame-alist '((width . 90) (height . 65)))

;; Remember password when connected to remote sites via Tramp
;; http://stackoverflow.com/questions/840279/passwords-in-emacs-tramp-mode-editing
;; Emacs "tramp" service (ssh connection) constantly
;; asks for the log in password without this
(setq password-cache-expiry nil)

;; Emacs shells work better
;; http://snarfed.org/why_i_run_shells_inside_emacs
(setq ansi-color-for-comint-mode 'filter)
(setq comint-prompt-read-only t)
(setq comint-scroll-to-bottom-on-input t)
(setq comint-scroll-to-bottom-on-output t)
(setq comint-move-point-for-output t)

pj-python-config.el

;; Python settings
(elpy-enable)
                          ;
;; recommended in elpy docs
(setq python-shell-interpreter "jupyter"
      python-shell-interpreter-args "console --simple-prompt"
      python-shell-prompt-detect-failure-warning nil)
(add-to-list 'python-shell-completion-native-disabled-interpreters
             "jupyter")
; https://stackoverflow.com/questions/25154809/how-can-i-stop-elpy-from-overriding-some-of-my-keybindings/25159354
; https://emacs.stackexchange.com/questions/46247/cannot-bind-m-s-left
(eval-after-load "elpy"
 '(progn
    (define-key elpy-mode-map [(control return)] nil)
    (define-key elpy-mode-map [(shift return)] 'elpy-shell-send-statement-and-step)
    (define-key elpy-mode-map (kbd "\M-\t") nil)
    (define-key elpy-mode-map (kbd "s-<tab>") 'elpy-company-backend)
    )
)
(setq elpy-rpc-timeout 10)

; specify interpreter
;(setq elpy-rpc-virtualenv-path 'current)
;(setq elpy-rpc-python-command "python3")
;(setq elpy-rpc-virtualenv-path 'current)
pauljohn32 commented 2 years ago

Forgot to explain that when I run this line-by-line, then the Windows Paint program "freezes" ELPY, Elpy can only run first of the plot commands. Here' picture elpy_plot-2022-04-11_20-18-22