CudaText-addons / cuda_lsp

LSP Client plugin for CudaText
2 stars 3 forks source link

abuout python env problems #176

Closed suiyuanla closed 1 year ago

suiyuanla commented 1 year ago

This plugin helps me to write python scripts,thanks. But I meet some problem about config lsp_pyright.I use the anaconda virtual env in anaconda3/envs/pytorch/python.exe for my project, but the pyright can't use this env .Such as "import torch",I can run this ,but pyright say it can't find this moudle. image and follow is my lsp_pyright.json image I'm a rookie in programing and my english is poor.Excuse me

suiyuanla commented 1 year ago

I think it maybe useful if I can run comand "conda activate pytorch" before the"pyright-langserver --stdio" .But I try "cmd_windows":["conda activate pytorch","pyright-langserver","--stdio"], it doesn't work

veksha commented 1 year ago

hi, @Adesince . what if you try "cmd_windows": ["pyright-langserver.exe", "-v" , "G:/anaconda3/envs/pytorch", "--stdio"],

suiyuanla commented 1 year ago

I try it and I create a file name "pyrightconfig.json" according the pright dom, image image image But it still doesn't work. I'm sure the path is right, because I can run this code.

veksha commented 1 year ago

Where is you CudaText project file saved?

suiyuanla commented 1 year ago

I make a test project image and the cudatext project file in: image

suiyuanla commented 1 year ago

And my anaconda env path is image I don't know why it doesn't work :(

veksha commented 1 year ago

in CudaText console you have line like this: LSP: starting server - Python; root: E:\.... right? this root folder is the folder of .cuda-proj file i think this root folder is important to pyright-langserver (like to any other lsp server)

in cuda_lsp config you have this setting: "root_dir_source": [ 0, 1, 2 ],

* root_dir_source - LSP server root directory source (accepts list of values for fallback):
    * 0 - parent directory of '.cuda-proj'
    * 1 - first directory in project
    * 2 - project main-file's directory

i think, to let pyright-langserver to read pyrightconfig.json, it must be located in root dir.

try to save your .cuda-proj to dir where pyrightconfig.json is located, and reopen it from there.

veksha commented 1 year ago

this worked for me in pyrightconfig.json:

{
  "stubPath": "G:/anaconda3/envs/pytorch/lib/site-packages"
}
veksha commented 1 year ago

image

veksha commented 1 year ago
  1. save .cuda-proj to dir where pyrightconfig.json is located
  2. configure stubPath in pyrightconfig.json
  3. restart CudaText
suiyuanla commented 1 year ago

I save the .cuda-proj in the project dir, it still doesn't work. Then I try to add the "stubPath" as you sat , amazingly It worked. I think I should read the pyright document carefully, I even don't konw the option "stubPath" . It works, thank you very much.😊😊

veksha commented 1 year ago

answer about stubPath was found here: https://github.com/emacs-lsp/lsp-pyright/issues/7 i don't know if this is correct approach, but it works.

veksha commented 1 year ago

also check lsp log in bottom panel. maybe python version is wrong still.

3.8 is global 3.10 in anaconda env

i see it assumes 3.8:

image

suiyuanla commented 1 year ago

It seems that the python 3.8 is cudatext's python environment. Because my global python version is 3.9.13, and my conda env version is 3.9.16. So I don,t know why lsp_server can't use the virtual python environment

suiyuanla commented 1 year ago

But I set the project python version is "3.9.16" in pyrightconfig.json, and the python path to excute the python script also is my conda env, so I think it isn't a problem maybe.