Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python interpreter not detected via C-c C-p and doesn't print anything#505

Unanswered
parvizfarnia asked this question inQ&A
Discussion options

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.

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

I managed to solve the first problem. I added the following to my Emacs init.el file :

(custom-set-variables;; =============== Other variables ================'(python-shell-interpreter "python"))

But the other problem persists, that is, doingC-c C-c doesn't print anything inside*Python* buffer.

You must be logged in to vote
1 reply
@parvizfarnia
Comment options

Any idea about why C-c C-c doesn't print the program output ?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@parvizfarnia

[8]ページ先頭

©2009-2025 Movatter.jp