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.