0

Some time ago, I asked this question, which is how to create new python shells that get renamed based on the script from which they are run, e.g., foo.py should create a shell *Python[foo.py]*, and foe.py creates *Python[foe.py]*. So far, that worked, but recently I needed to reinstall my OS, and hence Emacs. Now, when I try the same function, I get the error: NameError: name '__PYTHON_EL_eval_file' is not defined. It is the same error as as this question.

I hooked that function to C-c C-C. If I C-c C-c once the error is generated, but if I C-c C-c twice, then it works as expected. So, it seems by running C-c C-c once, the file is being generated.

This is the, according to my understanding, relevant code in my init.el file

(require 'python)


(use-package python-mode
  :ensure t
  :hook (python-mode . lsp-deferred)
  :custom
  (python-shell-interpreter "python"))

(use-package pyvenv
  :config
  (pyvenv-mode 1))

(setq python-shell-completion-native-enable nil)

(defun my-python-start-or-switch-rep (&optional msg)
"Start and/or switch to the REPL."
(interactive "p")
(if (python-shell-get-process)
    (progn
      (python-shell-send-buffer)
      (python-shell-switch-to-shell)
      )
  (progn
    (run-python (python-shell-calculate-command) t t)
    (other-window 1)
    (python-shell-send-buffer)
    (python-shell-switch-to-shell)
    )
  )
)

(add-hook 'python-mode-hook
      (lambda () (define-key python-mode-map (kbd "C-c C-c") 'my-python-start-or-switch-rep))
      )
(put 'upcase-region 'disabled nil)

I searched the web, but didn't really find a solution; maybe the solution is simple. I am an Emacs noob, and most of my stuff is what I found online/asked and tried to change, so that's why I feel helpless. I'd appreciate any help.

dalanicolai
  • 6,108
  • 7
  • 23
Schach21
  • 33
  • 8
  • Start with `M-x toggle-debug-on-error` and try again. Does it bring any new insights? (In that case add it to the question) – dalanicolai Nov 18 '22 at 04:52
  • I did it. Where should I see any debugging messages? I get the same error, but when `*Messages*`, and there was nothing there, or the ipython shell. I am not sure where else to search. – Schach21 Nov 18 '22 at 17:10
  • Update. I got an error that debugger tracked. It opened a buffer called `*Backtrace*`, however, that error is unrelated to this problem (the error was with lsp and completion). In other words, `M-x toggle-debug-on-error` is working, but somehow my problem is not triggering anything. – Schach21 Nov 18 '22 at 17:39
  • Okay, I guess it does not provide much useful info then. So what happens if you just do manually `M-: (run-python (python-shell-calculate-command) t t)`, then switch back to your python buffer and do `M-x python-shell-send-buffer`? – dalanicolai Nov 20 '22 at 08:22
  • It works. I don't get any error. I guess I can adapt my code using these commands. – Schach21 Nov 21 '22 at 00:25

0 Answers0