basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

import resolution for generic virtual environments

Open gennaro-tedesco opened this issue 1 month ago • 8 comments

First of all, thank you for the awesome project!

I am trying to come to terms with resolution of package imports within virtual environments (which I often found difficult in pyright as well): in particular I am referring to the import resolution section in the docs. Notice I have read https://github.com/DetachHead/basedpyright/issues/158 and https://github.com/DetachHead/basedpyright/issues/214 as well.

Description

I am using poetry to manage virtual environments: this means that virtual environments are generally created in some local paths ~/Library/pypoetry/virtualenvs/<projectname>-abc124... (or similar), with python packages locally installed are referred therein.

While running the project within the activated virtual environment, basedpyright always shows the diagnostic "Import could not be resolved" despite explicitly indicating the aforementioned path as per the documentation:

If a venv name is specified along with a python.venvPath setting (or a --venvpath command-line argument), it appends the venv name to the specified venv path...

The documentation moreover mentions

Use the python.pythonPath setting. This setting is defined by the VS Code Python extension and can be configured using the Python extension’s environment picker interface.

which is a little unclear to me if you are not using VS Code (the pythonPath is not a variable that even exists or is/must be explicitly set).

Attempts

[tool.basedpyright]
typeCheckingMode = "standard"
venvPath = "~/Library/pypoetry/virtualenvs/"  (or similar explicit path, or similar grammars)

What is the recommended way to specify paths to virtual environments for package resolution? (Notice I am referring to package imports and not relative imports from other modules, which work fine instead).

gennaro-tedesco avatar May 18 '24 04:05 gennaro-tedesco