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.

5
  • 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) Nov 18, 2022 at 4: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, 2022 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, 2022 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? Nov 20, 2022 at 8:22
  • It works. I don't get any error. I guess I can adapt my code using these commands.
    – Schach21
    Nov 21, 2022 at 0:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.