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

Editable installs (pip install -e) aren't fully supported #78

Closed
bobatsar opened this issue Jul 9, 2020 · 28 comments
Closed

Editable installs (pip install -e) aren't fully supported #78

bobatsar opened this issue Jul 9, 2020 · 28 comments
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@bobatsar
Copy link

bobatsar commented Jul 9, 2020

Environment data

  • Language Server version: Pylance language server 2020.6.1
  • OS and version: Ubuntu 20.04
  • Python version: Python 3.7.7

Expected behaviour

If python packages are installed in "develop" mode with

pip install -e package_name

code completion should work as normal.

Actual behaviour

Code completion is not working when packages are installed as "develop"

pip install -e package_name

When installing them normally with

pip install package_name

everything seems to work.

@erinxocon
Copy link

I wonder if this is related to my issue #70

My package isn't installed by pip but it is symlinked into the site packages folder like pip would do in editable mode.

@jakebailey
Copy link
Member

I do not believe we currently handle editable installs.

@jakebailey jakebailey added the enhancement New feature or request label Jul 9, 2020
@jakebailey jakebailey added the needs investigation Could be an issue - needs investigation label Aug 14, 2020
@wojtek-viirtue
Copy link

I can confirm the same as @bobatsar describes when using pipenv install -e. Installing a package normally everything works.

@jakebailey jakebailey changed the title development packages not resolved Editable installs aren't fully supported Nov 17, 2020
@jakebailey jakebailey changed the title Editable installs aren't fully supported Editable installs (pip install -e) aren't fully supported Nov 17, 2020
@zuozhiwen
Copy link

zuozhiwen commented Nov 27, 2020

so do i
still not work

@NiklasRosenstein
Copy link

Hey, I'm encountering the same issue with editable installs. Are there any plans to tackle this issue? I'm also happy to look into contributing a fix, but I may need a pointer in the right direction. 🙂

@jakebailey
Copy link
Member

Any updates we have will be posted here; I know we want to look into this but it will take some care to get right. There are other things that have taken priority over working on editable installs / pth files.

You could look at the pyright import resolver and path system to see what might be needed, but having personally added editable install support to the old language server previously, it may be tricky. (Or, it may be a simple bug, given we are supposed to be using the paths given by the interpreter and edtiable installs install pth files which modify what Python tell us.)

@erictraut
Copy link
Contributor

Yeah, this is a tricky area of the code. I'd prefer that you don't attempt any changes. If you want to debug and report back, that'd be fine.

@jakebailey
Copy link
Member

After looking at this code for another bug, there are a couple places that stand out as problematic in the current code. The main thing is that with editable installs, the interpreter provides the paths, so that's what we want to work. findPythonSearchPaths explicitly ignores paths in the workspace that are not also inside of the venv (so pth files pointing to workspace dirs doesn't work), and getPythonPathFromPythonInterpreter caches the result globally and never clears it on file update. By cutting out that first check, and then moving this cache to the import resolver (which is cleared on reconfig, or similar, or remove the cache entirely), it's likely we can make this work.

@jakebailey
Copy link
Member

jakebailey commented Feb 4, 2021

Noting this as another example to use for testing: #892 (comment)

@mjmaurer
Copy link

mjmaurer commented Feb 6, 2021

If anyone is looking for a VSCode solution in the meantime, you can add something like:

    "python.analysis.extraPaths": [
        "vendor/django-allauth",
        "vendor/dj-rest-auth",
    ],

to your settings.

@erictraut
Copy link
Contributor

@jakebailey, I think this should fully work now.

@jakebailey
Copy link
Member

jakebailey commented Mar 12, 2021

I believe it only works so long as the code you added to parse pth files by hand is triggered (and the pth file does not contain anything but strings; not true for libraries like matplotlib or pywin32)

In the case of a regular interpreter where that code is not used and we are relying on it to read sys.path (which should be almost always in Pylance), there was still the question as to what was going wrong that needs some debugging. My analysis in #78 (comment) was wrong (which I figured out when you made your change), so I'd like to recheck.

@jakebailey
Copy link
Member

I've tested it out, and things do work as expected, but only the first time things load. There's a global cache in front of our calls to python for path info which means that when the file watcher detects that the new package has been installed (the egg-link is created), we still return the old results. This cache is never cleared.

As far as I can tell, there are only a few uses of the call to python. Two of them only run on settings change, and the rest come from the import resolver which has another cache for this function specifically (that is cleared on import resolver invalidation, which happens on library changes). So, I think that it's safe for us to just remove this cache, and then editable installs will work both on first load and pip install -e . at runtime.

@jakebailey
Copy link
Member

At this point (besides needing to force a restart when changing things while Pylance is running), I believe editable installs to be working.

I'd appreciate if those watching this thread who use editable installs could confirm that things work as expected. Pinging a few who have commented (sorry 🙂): @bobatsar @erinxocon @NiklasRosenstein @wojtek-viirtue @zuozhiwen @mjmaurer

@jakebailey jakebailey removed in backlog needs investigation Could be an issue - needs investigation labels Mar 12, 2021
@jakebailey jakebailey added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Mar 12, 2021
@bobatsar
Copy link
Author

@jakebailey on my side it seems good now.
I don't know if this fix has already landed (I am now on VSCode 1.54.3, python extension 2021.3.0 and pylance v2021.3.1) but my original issues seems to be gone.
Thanks. From my side this can be closed.

@jakebailey
Copy link
Member

This issue has been fixed in version 2021.3.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202132-17-march-2021

@mohsenBanan
Copy link

I am seeing this same problem with pyright (integrated into emacs).
I am using pyright --version
pyright 1.1.163
Has there been a fix for pyright as well?

@jakebailey
Copy link
Member

Yes, the same code is present in both. You may want to file a new issue on the pyright tracker (if your issue is pyright focused); this one has been closed for 6 months.

@rupeshknn
Copy link

I still get Missing Imports warning for pylance in vs-code notebooks. (works fine on scripts) I understand this could be outside the scope of this repo. But does anyone have a suggestion?

@debonte
Copy link
Contributor

debonte commented Sep 21, 2022

@rupeshknn, this issue has been closed for more than a year. Please file a new issue on the behavior your are seeing.

@bobatsar
Copy link
Author

I don't know if anything changed but it seems it is not working any longer on my side. Should I open another ticket or can this be reopened?

@debonte
Copy link
Contributor

debonte commented Nov 14, 2022

I don't know if anything changed but it seems it is not working any longer on my side. Should I open another ticket or can this be reopened?

@bobatsar, please read https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#editable-install-modules-not-found. If the issue described there is not what you are encountering, please open a new issue.

@bobatsar
Copy link
Author

Thanks @debonte for the link. I didn't know that there were some changes in the underlying handling of editable installs.

@oakla
Copy link

oakla commented May 3, 2023

If anyone is looking for a VSCode solution in the meantime, you can add something like:

    "python.analysis.extraPaths": [
          "vendor/django-allauth",
          "vendor/dj-rest-auth",
    ],

to your settings.

The extra paths should point to the root of the project (in case this isn't clear to anyone)

    "python.analysis.extraPaths": [
        "<path-to-project-root-of-editable-installed-package>",
    ],

@SingL3
Copy link

SingL3 commented Jul 21, 2023

My solution not to change the vscode setting is to install in compat mode:

pip install -e . --config-settings editable_mode=compat

@littlecutebird
Copy link

My solution not to change the vscode setting is to install in compat mode:

pip install -e . --config-settings editable_mode=compat

worked for me. Ty so much!

@aylusltd
Copy link

My solution not to change the vscode setting is to install in compat mode:

pip install -e . --config-settings editable_mode=compat

worked for me. Ty so much!

I tried that but get the following error:

no such option: --config-settings

Python version 3.11, virtual environment, Ubuntu 22.04 on WSL.

@Speedlulu
Copy link

My solution not to change the vscode setting is to install in compat mode:

pip install -e . --config-settings editable_mode=compat

worked for me. Ty so much!

I tried that but get the following error:

no such option: --config-settings

Python version 3.11, virtual environment, Ubuntu 22.04 on WSL.

This is probably due to this : https://setuptools.pypa.io/en/latest/userguide/development_mode.html#legacy-behavior :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests