Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup the python environment? #1228

Closed
3 tasks done
SimFG opened this issue Apr 11, 2024 · 32 comments
Closed
3 tasks done

How to setup the python environment? #1228

SimFG opened this issue Apr 11, 2024 · 32 comments
Labels
env Issues caused by incorrect environment settings (terminal, package manager, etc.) pylsp Python LSP Server related issues

Comments

@SimFG
Copy link

SimFG commented Apr 11, 2024

Version confirmation

  • Confirm

Following prerequisites

  • Confirm

Not a user config issue

  • Confirm

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

@SimFG SimFG added the bug Something isn't working label Apr 11, 2024
@CharlesChiuGit CharlesChiuGit added env Issues caused by incorrect environment settings (terminal, package manager, etc.) pylsp Python LSP Server related issues and removed bug Something isn't working labels Apr 11, 2024
@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Apr 11, 2024

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

@ayamir
Copy link
Owner

ayamir commented Apr 11, 2024

#1113 (comment)

@SimFG
Copy link
Author

SimFG commented Apr 11, 2024

@CharlesChiuGit i had done it.
image
image

@CharlesChiuGit
Copy link
Collaborator

did mason.log suggest anything?

@SimFG
Copy link
Author

SimFG commented Apr 11, 2024

where is the mason.log

@CharlesChiuGit
Copy link
Collaborator

@SimFG

where is the mason.log

Use :MasonLog

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

@SimFG
Copy link
Author

SimFG commented Apr 15, 2024

@CharlesChiuGit sorry for the late reply
image

@CharlesChiuGit
Copy link
Collaborator

hmmm, seems normal in mason.log

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Apr 15, 2024

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

@SimFG
Copy link
Author

SimFG commented Apr 15, 2024

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

@SimFG
Copy link
Author

SimFG commented Apr 15, 2024

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

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Apr 15, 2024

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
Copy link
Owner

ayamir commented Apr 15, 2024

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

@SimFG
Copy link
Author

SimFG commented Apr 16, 2024

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

@Jint-lzxy
Copy link
Collaborator

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
Copy link
Author

SimFG commented Apr 18, 2024

@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
Copy link
Collaborator

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
Copy link
Collaborator

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

check our wiki on how to do it.

@SimFG
Copy link
Author

SimFG commented Apr 18, 2024

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

@CharlesChiuGit
Copy link
Collaborator

@ayamir
Copy link
Owner

ayamir commented Apr 18, 2024

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

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

image

@ayamir
Copy link
Owner

ayamir commented Apr 18, 2024

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

@SimFG
Copy link
Author

SimFG commented Apr 18, 2024

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

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Apr 18, 2024

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
Copy link
Author

SimFG commented Apr 18, 2024

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
Copy link
Collaborator

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

@CharlesChiuGit
Copy link
Collaborator

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

@SimFG
Copy link
Author

SimFG commented Apr 18, 2024

@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
Copy link
Collaborator

CharlesChiuGit commented Apr 18, 2024

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
Copy link
Author

SimFG commented Apr 18, 2024

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

@SimFG SimFG closed this as completed Apr 18, 2024
@SimFG
Copy link
Author

SimFG commented Apr 18, 2024

:LspInfo
image
:NullLsInfo
image

@CharlesChiuGit
Copy link
Collaborator

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

@SimFG SimFG reopened this Apr 18, 2024
@SimFG SimFG closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
env Issues caused by incorrect environment settings (terminal, package manager, etc.) pylsp Python LSP Server related issues
Projects
None yet
Development

No branches or pull requests

4 participants