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

Resolve local package installed with pip install -e . #1473

Closed
vpeopleonatank opened this issue Feb 11, 2021 · 14 comments
Closed

Resolve local package installed with pip install -e . #1473

vpeopleonatank opened this issue Feb 11, 2021 · 14 comments

Comments

@vpeopleonatank
Copy link

I cloned a python package repository. If I use command pip install -e . to install package in development mode, pyright can't resolve it. But with pip install ., pyright resolve that package normally. Is this a bug or needing an enhancement?

@jakebailey
Copy link
Member

See also: microsoft/pylance-release#78

I haven't looked into this, but I think this is because we remove paths that point into the workspace but are outside the interpreter prefix (which is usually editable installs pointing into the works).

@vpeopleonatank
Copy link
Author

Thanks for pointing out related issue. I saw a temporary solution by adding an extra path in pyrightconfig.json. Thanks

@erictraut erictraut added the needs investigation Requires additional investigation to determine course of action label Feb 11, 2021
@erictraut
Copy link
Collaborator

Can you provide specific repro steps? I'm looking for a specific example of a package that doesn't work when it is installed using editable install.

@vpeopleonatank
Copy link
Author

Here is package repo https://github.com/qubvel/segmentation_models.pytorch .I cloned and pip install -e .. But It doesn't work

@erictraut
Copy link
Collaborator

I cloned this repo, installed it with install -e ., then restarted the language server (you can do this by quitting and launching VS Code). I was then able to resolve imports to it. So there must be a difference between your configuration and mine.

How are you specifying your python environment? Are you using the environment selector within VS Code (the one provided by the Python extension)? Or are you using a "pyrightconfig.json" file and specifying a "venv" setting?

@vpeopleonatank
Copy link
Author

I 'm using pyrightconfig.json for specifying python environment. I saw that after remove pyrightconfig.json, It can resolve the package installed with pip install -e .. Thanks for your help!

@erictraut
Copy link
Collaborator

If you use the "venv" setting in pyrightconfig, pyright uses its own internal logic to find the site-packages path in the venv. That logic doesn't currently look for any ".pth" files (which I didn't know existed before digging into this bug). If you don't use the "venv" setting in pyrightconfig, pyright falls back to the selected Python interpreter and asks it to enumerate all of its search paths. That list includes any paths added via ".pth" files, which is why it works in that case.

Arguably, the internal logic used in the "venv" case should be enhanced to know about ".pth" files, but if you're happy with the workaround, I'm fine closing this issue.

@vpeopleonatank
Copy link
Author

Actually in some case, I need to use pyrightconfig.json to specify excutionEnvironment 's root. But I'm still happy with current pyright setup.

@erictraut
Copy link
Collaborator

To be clear, you can still use pyrightconfig.json and specify different executionEnvironment roots. You just can't specify the "venv" setting.

@vpeopleonatank
Copy link
Author

After searching for some issues, activate conda env and open neovim in terminal, pyright can use activated python env. It satisfies my need now.

@erictraut erictraut removed the needs investigation Requires additional investigation to determine course of action label Feb 21, 2021
heejaechang added a commit to heejaechang/pyright that referenced this issue Nov 3, 2021
@fakedrake
Copy link

fakedrake commented Oct 30, 2022

Sorry to revive this old issue but being very new to pyright I am a bit confused that this issue is closed and yet the following happens:

(TL;DR: Python sees pip install -e .-ed module by pyright doesn't)

$ mkdir -p /tmp/dummy && cd /tmp/dummy && echo 'import cellprofiler_core' > test.py
$ pyright                                                                          
No configuration file found.
No pyproject.toml file found.
stubPath /private/tmp/dummy/typings is not a valid directory.
Assuming Python platform Darwin
Searching for source files
Found 1 source file
pyright 1.1.277
/private/tmp/dummy/test.py
  /private/tmp/dummy/test.py:1:8 - error: Import "cellprofiler_core" could not be resolved (reportMissingImports)
1 error, 0 warnings, 0 informations 
Completed in 0.468sec 
$ which pyright
/opt/homebrew/bin/pyright
$ which python3 # Not in a venv
/opt/homebrew/bin/python3
$ pyright --version
pyright 1.1.277
$ python3 --version
Python 3.10.8          
$ python3 -c 'import cellprofiler_core; print(cellprofiler_core.__file__)' # in editable mode
/Users/fakedrake/Projects/cellprofiler_core/cellprofiler_core/__init__.py

Maybe I am missing some nuance?

@erictraut
Copy link
Collaborator

This is an old issue, and the original problem was fixed long ago.

The problem you're now experiencing is a new problem introduced in PEP 660 and recent releases of setuptools. These changes made editable installs incompatible with all static analysis tools. The static typing community warned the authors of PEP 660 and setuptools that this would happen, but they unfortunately decided to go ahead with the change anyway. Now the broader Python community is experiencing this pain.

For more details and workarounds, refer to this documentation.

@fakedrake
Copy link

That's unfortunate. Thanks for the link, much appreciated!

@fakedrake
Copy link

fakedrake commented Oct 30, 2022

For posterity, what ended up working was to add a pyrightconfig.json to the root of containing the following

{
    "extraPaths": ["/Users/fakedrake/Projects/cellprofiler_core"]
}

And I could also make it work by adding the following to my pyproject.toml but I don't want to impose that on the users and it just so happens that I can put pyrightconfig.json in gitignore.

[tool.pyright]
extraPaths = ['../cellprofiler_core']

(Note how relative paths work for pyproject.toml but not for pyrightconfig.json. I don't know why that is.)

I wish there were a way to define a user wide ~/.pyrightconfig.json or something like that. Is there such a feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants