ayamir / nvimdots

A well configured and structured Neovim.
BSD 3-Clause "New" or "Revised" License
2.82k stars 450 forks source link

How to setup the python environment? #1228

Closed SimFG closed 2 months ago

SimFG commented 2 months ago

Version confirmation

Following prerequisites

Not a user config issue

Neovim version

v0.9.5

Operating system/version

macOS 13.0.1

Terminal name/version

iterm2 Build 3.4.15

$TERM environment variable

No response

Branch info

main (Default/Latest)

Fetch Preferences

SSH (use_ssh = true)

How to reproduce the issue

when i open my python project, but there are many import error. what should i do to solve it? thanks a lot for your help and precious time. i have install the pvnivm for the python. image

Expected behavior

there is no import error

Actual behavior

No response

Additional information

No response

CharlesChiuGit commented 2 months ago

how do u set up your python env? did u enter the venv before opening any file in nvim?

ayamir commented 2 months ago

https://github.com/ayamir/nvimdots/issues/1113#issuecomment-1868824151

SimFG commented 2 months ago

@CharlesChiuGit i had done it. image image

CharlesChiuGit commented 2 months ago

did mason.log suggest anything?

SimFG commented 2 months ago

where is the mason.log

CharlesChiuGit commented 2 months ago

@SimFG

where is the mason.log

Use :MasonLog

https://github.com/williamboman/mason.nvim?tab=readme-ov-file#commands

SimFG commented 2 months ago

@CharlesChiuGit sorry for the late reply image

CharlesChiuGit commented 2 months ago

hmmm, seems normal in mason.log

CharlesChiuGit commented 2 months ago

u r sure 'pynvim' is installed in current python env? or u installed in the global python?

SimFG commented 2 months ago

@CharlesChiuGit i have install the pynvim in the current python env. image but in the global python, i don't.

SimFG commented 2 months ago

i install the pynvim in the global env, it doesn't take effect.

CharlesChiuGit commented 2 months ago

hmmm, i'm not sure why. Mine works fine. image image image

Env info: OS: macOS 14.4.1 python: 3.12.3 neovim: NVIM v0.10.0-dev-2560+gf879a6545-Homebrew nvimconfig: https://github.com/CharlesChiuGit/nvimdots.lua (my personal config, but it should perform the same on most part.)

ayamir commented 2 months ago

Can't repro for me too. Try using pyright? :MasonInstall pyright and MasonUninstall pylsp

SimFG commented 2 months ago

@ayamir I tried executing them, but it still doesn't work

Jint-lzxy commented 2 months ago

Not exactly a Python expert, but a skim through the docs seems to suggest that pyright/pylsp has a pretty robust venv detection regime. AFAIU to fix this issue, u could create a pyrightconfig.json in ur project's root directory and drop in this (correct me if I'm off base lol):

{
  "venv": "<name-of-the-venv>"
  "venvPath": "/path/to/venv",
}

If that tweak does the trick (with pyright), it's likely because pylsp's getting mixed up about where to look for venvs (it's only checking out the dirname of these items). So, to sort this out right, u might need to tweak its config to point straight to the files in ur project root.

SimFG commented 2 months ago

@CharlesChiuGit When i uninstall the pylsp, and close the nvim. and then open the nvim, it auto install the pylsp and doesn't seem to use the pyright image

CharlesChiuGit commented 2 months ago

u install/uninstall pylsp in your venv? no need at all. mason install all lsp in it's own venv. check mason's help for more info. it's usually in "~/.local/share/mason"

CharlesChiuGit commented 2 months ago

u also need to disable pylsp in "lua/core/settings.lua" and config pyright .

check our wiki on how to do it.

SimFG commented 2 months ago

No matter what I try, nothing seems to work. 😥

CharlesChiuGit commented 2 months ago

https://github.com/ayamir/nvimdots/wiki/Usage#modify-lsps-linters-and-formatters

ayamir commented 2 months ago

https://github.com/ayamir/nvimdots/wiki/Usage#modify-lsps-linters-and-formatters

@SimFG or just remove it in core/settings.lua temprarily.

image
ayamir commented 2 months ago

Actually I also want to know basedpyright whether is good enough to replace pylsp as @CharlesChiuGit mentioned in #1172.

SimFG commented 2 months ago

image so so so so ... god 😵‍💫

CharlesChiuGit commented 2 months ago

hmmm, it got me thinking maybe the error is from jedi-lsp or other linter/formater u config in null-ls

plz make sure your env is 100% the same as our default config, otherwise we cant debug.

SimFG commented 2 months ago

there are all my diff. and i use the conda to manage the python environment. image image image image image image image image image image

CharlesChiuGit commented 2 months ago

Try :MasonUninstallAll and open nvim again too reinstall all lsp in the config. Also screenshot :NullLsInfo and check what linter you have installed.

CharlesChiuGit commented 2 months ago

u can also use :Trouble to check which lsp is generating the warnings.

SimFG commented 2 months ago

@CharlesChiuGit after reinstall all lsp, it seem to work fine. But it seems that * can't recognize it. I don't know if it's normal. image

CharlesChiuGit commented 2 months ago

that's 100% normal since it's not the pythonic way to do import and it's unsafe. it's better to only import the things u need.

So can u show us what's your :LspInfo and :NullLsInfo now?

SimFG commented 2 months ago

@CharlesChiuGit @ayamir Thanks a lot lot lot !!!

SimFG commented 2 months ago

:LspInfo image :NullLsInfo image

CharlesChiuGit commented 2 months ago

yeah, it looks like jedi-lsp's or null-ls linter's issue.