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

IntelliSense doesn't work in some third-party packages. But when Pylance is disabled, the IntelliSense can work. #6556

Closed
Zionshang opened this issue Oct 15, 2024 · 2 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@Zionshang
Copy link

Environment data

  • Pylance version: v2024.10.1
  • OS and version: Ubuntu20.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.10
  • Editor: vscode

Code Snippet

I installed the package mujoco via pip.

pip3 install mujoco

In python, the following code can be run successfully

import mujoco

xml = """......"""  # value has been ignored
model = mujoco.MjModel.from_xml_string(xml)

But neither autocomplete nor IntelliSense work
Image
Image

Repro Steps

I've tried a few methods

  1. Choose the right interpreter
    Image width="40%"
    All the interpreters have tried, but nothing works
  2. Edit the file settings.json in User environmet.
    "python.languageServer": "Pylance",
    "python.analysis.extraPaths": [
        "~/.local/lib/python3.8/site-packages"
    ],
    "python.autoComplete.extraPaths": [
        "~/.local/lib/python3.8/site-packages"
    ]

I've determined the package is installed at ~/.local/lib/python3.8/site-packages via pip3 show mujoco. But still not working.

Expected behavior

I found out when I disable the Pylance by

    "python.languageServer": "Jedi",

Image

the autocomplete and IntelliSense can work normally.
Image
Image
Image

Actual behavior

What is strange to me is that some packages like numpy are installed in the same path with mujoco, but numpy 's autocomplete and intellisense can work normally.
Image

Summary

Is this a problem with the mujoco package or a problem with Pylance?

  • If it is a problem with the package, why does the IntelliSense work after Pylance is disabled?
  • If it is a problem with Pylance, why does numpy's IntelliSense work?

I would be very grateful if you could answer that question, because I spent a long time on it.

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Oct 15, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Oct 15, 2024

Thanks for the issue. The "problem" here is that Mujoco is a wrapper around native code. Pylance cannot read native code in order to find the necessary information to display your intellisense. This is because Pylance doesn't run python code. It's a static analyzer.

You can tell that by looking at the install of Mujoco:

Image

A good portion of the public interface is in .pyd files (native python modules).

Mujoco would have to provide type stubs in order for Pylance to find the necessary information.

See this issue from Mujoco where people had similar problems with Pycharm:
google-deepmind/mujoco#244

Jedi, on the other hand, is a python app. It actually loads Mujoco into a python runtime and can inspect the native parts that way.

@Zionshang
Copy link
Author

@rchiodo Thank you for the answer, very thorough and concise!

@rchiodo rchiodo closed this as completed Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants