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

Pylance unable to correctly resolve local python packages installed in WSL Ubuntu in vscode WSL remote mode. #1046

Closed
gzimmers opened this issue Mar 14, 2021 · 11 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@gzimmers
Copy link

Environment data

  • Language Server version: 2021.3.1
  • OS and version: linux x64
  • Python 3.8.2
  • pip 21.0.1
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: off

More environment information

  • Windows 2004 build 19041.867
  • WSL version: 2
  • Distributor ID: Ubuntu
  • Description: Ubuntu 20.04 LTS
  • Release: 20.04
  • Codename: focal

Expected behaviour

Given this package structure and contents.

garbage
├── garbage
│   ├── test.py
│   ├── trash.py
│   └── __init__.py
└── setup.py

__init__.py is empty
test.py is empty
trash.py contents below

def trashfunc():
    print("hello")

My setup.py contents

from setuptools import setup, find_packages

setup(
    name='garbage',
    version="0.0.1", # type: ignore
    packages=find_packages(exclude=('tests', 'docs')),
    python_requires='>=3.8',
)

pylance should recognize the packages namespace correctly and suggest/be aware of the packages contents.

import garbage.trash import trashfunc

should invoke pylance suggestions and hints.

Actual behaviour

If I attempt to import the package pylance is unable to correctly resolve the packages namespace and suggests the incorrect namespace.

image

If I use the correct namespace of the package, my script will run successfully but pylance is unable to resolve it.

image

Logs

Python Language Server Log

[Info  - 10:55:52 PM] Pylance language server 2021.3.1 (pyright 5d6db8d1) starting
[Info  - 10:55:52 PM] Server root directory: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist
[Info  - 10:55:52 PM] No configuration file found.
[Info  - 10:55:52 PM] Setting pythonPath for service "plutus": "/home/greg/workspace/venv/plutus/bin/python"
Search paths found for configured python interpreter:
  /usr/lib/python3.8
  /usr/lib/python3.8/lib-dynload
  /home/greg/workspace/venv/plutus/lib/python3.8/site-packages
  /home/greg/workspace/plutus/plutusapi
  /home/greg/workspace/plutus/garbage
[Error - 10:55:52 PM] stubPath /home/greg/workspace/plutus/typings is not a valid directory.
[Info  - 10:55:52 PM] Assuming Python version 3.8
[Info  - 10:55:52 PM] Assuming Python platform Linux
[Info  - 10:55:52 PM] Searching for source files
[Info  - 10:55:52 PM] Found 10 source files
[Info  - 10:55:52 PM] Background analysis(1) root directory: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist
[Info  - 10:55:52 PM] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: ensurePartialStubPackages
Background analysis message: setFileOpened
Background analysis message: getSemanticTokens
[BG(1)] parsing: /home/greg/workspace/plutus/garbage/garbage/test.py (15ms)
[BG(1)] parsing: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 2ms] (77ms)
[BG(1)] binding: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist/typeshed-fallback/stdlib/builtins.pyi (33ms)
[BG(1)] binding: /home/greg/workspace/plutus/garbage/garbage/test.py (2ms)
[BG(1)] parsing: /home/greg/workspace/plutus/garbage/garbage/trash.py [fs read 0ms] (2ms)
[BG(1)] binding: /home/greg/workspace/plutus/garbage/garbage/trash.py (1ms)
Background analysis message: getSemanticTokens
Background analysis message: analyze
[BG(1)] analyzing: /home/greg/workspace/plutus/garbage/garbage/test.py ...
[BG(1)]   checking: /home/greg/workspace/plutus/garbage/garbage/test.py ...
[BG(1)]     parsing: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 0ms] (14ms)
[BG(1)]     binding: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (2ms)
[BG(1)]     parsing: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist/typeshed-fallback/stdlib/typing.pyi [fs read 1ms] (28ms)
[BG(1)]     binding: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist/typeshed-fallback/stdlib/typing.pyi (12ms)
[BG(1)]     parsing: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist/typeshed-fallback/stubs/typing-extensions/typing_extensions.pyi [fs read 1ms] (3ms)
[BG(1)]     binding: /home/greg/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.1/dist/typeshed-fallback/stubs/typing-extensions/typing_extensions.pyi (1ms)
[BG(1)]   checking: /home/greg/workspace/plutus/garbage/garbage/test.py (86ms)
[BG(1)] analyzing: /home/greg/workspace/plutus/garbage/garbage/test.py (86ms)
Background analysis message: resumeAnalysis
[FG] completion at /home/greg/workspace/plutus/garbage/garbage/test.py:0:13 ...
[FG]   parsing: /home/greg/workspace/plutus/garbage/garbage/test.py (1ms)
[FG]   binding: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
[FG] completion at /home/greg/workspace/plutus/garbage/garbage/test.py:0:13 [found 4 items] (1ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens
[BG(1)] parsing: /home/greg/workspace/plutus/garbage/garbage/test.py (1ms)
[BG(1)] binding: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
[FG] completion at /home/greg/workspace/plutus/garbage/garbage/test.py:0:14 ...
[FG]   parsing: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
[FG]   binding: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
[FG] completion at /home/greg/workspace/plutus/garbage/garbage/test.py:0:14 [found 3 items] (1ms)
[FG] completion at /home/greg/workspace/plutus/garbage/garbage/test.py:0:15 ...
[FG]   parsing: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
[FG]   binding: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
[FG] completion at /home/greg/workspace/plutus/garbage/garbage/test.py:0:15 [found 1 items] (1ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens
[BG(1)] parsing: /home/greg/workspace/plutus/garbage/garbage/test.py (4ms)
[BG(1)] binding: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
[FG] parsing: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
[FG] binding: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
Background analysis message: getSemanticTokens
[BG(1)] parsing: /home/greg/workspace/plutus/garbage/garbage/test.py (1ms)
[BG(1)] binding: /home/greg/workspace/plutus/garbage/garbage/test.py (0ms)
Background analysis message: analyze
[BG(1)] analyzing: /home/greg/workspace/plutus/garbage/garbage/test.py ...
[BG(1)]   checking: /home/greg/workspace/plutus/garbage/garbage/test.py (7ms)
[BG(1)] analyzing: /home/greg/workspace/plutus/garbage/garbage/test.py (7ms)
Background analysis message: resumeAnalysis
@gzimmers
Copy link
Author

gzimmers commented Mar 14, 2021

I've attempted to uninstall and reinstall pylance and my virtual environment setup a couple times and on another machine, and every time I get a broken setup, but the brokenness varies. Sometimes pylance becomes correctly aware that it should be garbage.trash but will still try and suggest garbage.garbage.trash as a viable namespace.

Let me know if there are any other tests or info you may need.

@judej
Copy link
Contributor

judej commented Mar 15, 2021

Thanks for the report. Will investigate this. Have two questions:

  1. Are you using editable installs?
  2. Is there a repo where we can test this?

Thanks!

@judej judej added needs investigation Could be an issue - needs investigation waiting for user response Requires more information from user labels Mar 15, 2021
@github-actions github-actions bot removed the triage label Mar 15, 2021
@gzimmers
Copy link
Author

1.) I've attempted the installation with both editable installs and non-editable installs. Both of which result in funky behavior.

2.) I can create a repository later tonight and link it.
In the example repository, I'll create a simple python package that I can recreate the issue with. Is there anything else you'd like in the repository? Like a virtualenv setup script that creates an environment and installs the 'bad' package?

@jakebailey
Copy link
Member

Our normal solution is to recommend setting an extraPath to explicitly list your import roots (we have no idea that you need to import relative to a subfolder of the workspace without configuration); the editable install would have made that unnecessary so that's confusing (hence wanting a repro).

Doesn't have to be as automated as a script, so long as it's clear what to do.

@jakebailey jakebailey removed the needs investigation Could be an issue - needs investigation label Mar 16, 2021
@gzimmers
Copy link
Author

Here is the example repository.

The issue can be repeated with both pip install -e . and pip install .. I will say that pip install -e . results in a "more" broken setup than the outright install of the package.

https://github.com/gzimmers/pylanceissue

@erictraut
Copy link
Contributor

Your example seems to work fine for me on MacOS.

I replaced the contents of script.py with:

from pylancemodule.submodule import test_function
test_function()

After doing the editable install in your shell script, I'm able to run script.py fine in the Python interpreter (it outputs "hello world"), and Pylance analyzes it without errors.

I confirmed that there's a symbolic link called pylancemodule.egg-link installed in my site-packages directory, and it points to the local package directory. I've also confirmed that the Python interpreter is adding this directory to sys.path, and pylance is picking up this new path.

Does this match what you're seeing? I'm wondering if the problem is specific to Linux (or your specific version of Ubuntu).

@gzimmers
Copy link
Author

gzimmers commented Mar 19, 2021

Yes it does work correctly on MacOS, as I generally develop on MacOS. It seems to be only a WSL Remote mode problem. I haven't tried Ubuntu recently, but I'd be willing wager it probably works fine on Ubuntu as well, but maybe it's possible it can be recreated in Ubuntu outright.

@jakebailey jakebailey added needs investigation Could be an issue - needs investigation and removed waiting for user response Requires more information from user labels Mar 19, 2021
@jackdewinter
Copy link

I have this same problem on my win10 setup, with WSL2-Ubuntu. Willing to help out if needed.

@KyryloKaralyus
Copy link

I have the same issue, still no fix :C

@jakebailey jakebailey added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed needs investigation Could be an issue - needs investigation labels Sep 1, 2021
@jakebailey
Copy link
Member

The next release fixes the import completions to not offer up items that won't resolve when accepted.

@jakebailey
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

7 participants