Hello everyone and Merry Christmas My environment: - Emacs version 29.1- Python version : 3.12.0 (64 bit)- OS : Windows 11
Here is how I proceeded to installpython-lsp-server : - First, I created a new virtual environment (Python-3.12.0-64 bit)
- Second, I enabled this new environment and within the same terminal I run emacs in background (
start /B runemacs.exe ) - And then, I returned to the same terminal and I installed the following packages:
pip install "python-lsp-server[all]"pip install pylsp-mypypip install python-lsp-isortpip install pylsp-ropepip install pyls-memestrapip install pylsp-ropepip install python-lsp-ruff
Then I came back to Emacs and I installed the following packages from MELPA: M-x package-install [RET] lsp-mode [RET]M-x package-install [RET] lsp-ui [RET]M-x package-install [RET] flycheck [RET]M-x package-install [RET] helm-lsp [RET]M-x package-install [RET] lsp-treemacs [RET]
And finally I put the following in my Emacs configuration file (org file) to enablelsp-mode forPython : (use-package lsp-ui) (lsp-treemacs-sync-mode 1) (define-key lsp-mode-map [remap xref-find-apropos] #'helm-lsp-workspace-symbol) (require 'lsp-mode) (add-hook 'python-mode-hook #'lsp)
Generally, it seems that it is working. However, I have currently two issues: As I said, first, I enabled my Python virtual environment and then, within the very same terminal, I launched Emacs in background. My requirement is thatlsp should consider as Python interpreter, the same interpreter of the currently running virtual environment (Python 3.12.0). However, due to some technical constraints, I have not added that interpreter in myPATH environment variable. Currently only Python 3.10 is in myPATH . Consequently when I runC-c C-p to start a Python process, it opens a Python 3.10 shell instead of 3.12. Therefore, I need a way to telllsp client to take the very Python interpreter used bylsp-server , which is that of the current running virtual environment. After runningC-c C-p if I come back to my Python program buffer and doC-c C-c in order to send the current buffer to Python process for running, nothing happens and the result is not printed, there is no output. Consider the following example:
def main(): """Print Hello.""" print("Hello World")if __name__ == "__main__": main()
If I doC-c C-c within the buffer containing the above program, then the only thing that happens in*Python* buffer (Python process launched via C-c C-p) is a new prompt line>>> which is added and that's all. No "Hello World" message is printed as if the Standard Output was not available. I even introduced a syntax error in the program to see whether doingC-c C-c will cause the*Python* process buffer print an error message, but again, the same problem only a new prompt line>>> is added. I wonder whether this*Python* process communicates at all with the buffer containing my Python program. Therefore, I would like to know what is wrong with my configuration and how to solve these issues. Thanks in advance. |