admin管理员组

文章数量:1122846

I'm working with Python in an environment where there are some classes which are defined externally (as in, I don't have access to the files where these classes are defined). So I can import these classes and use them, but since VSCode can't resolve the import, there's no autocomplete for them.

What I would want: a way to tell VSCode which attributes and methods these classes have, so it can autocomplete for me whenever I use them (same as if I had these classes defined in my workspace and imported normally). Is this possible somehow?

I'm working with Python in an environment where there are some classes which are defined externally (as in, I don't have access to the files where these classes are defined). So I can import these classes and use them, but since VSCode can't resolve the import, there's no autocomplete for them.

What I would want: a way to tell VSCode which attributes and methods these classes have, so it can autocomplete for me whenever I use them (same as if I had these classes defined in my workspace and imported normally). Is this possible somehow?

Share Improve this question asked Nov 21, 2024 at 17:32 Julian LJulian L 1351 silver badge5 bronze badges 2
  • VS Code doesn't really do the intellisense work. Extensions like IntelliCode and Pylance create the functionality you're looking for. If intellisense programs can't find or recognize the classes in your environment, they won't give you intelligent recommendations and code completion for them. If you aren't using IntelliCode or Pylance, try that first. If that doesn't help, you could write copies of the classes in your own local module to import (if you're able to read them). – Mason Ritchason Commented Nov 21, 2024 at 20:39
  • 1 However, I did just find a setting in VS Code settings called Python > Auto Complete: Extra Paths. I don't know exactly what environment you are pulling these classes from, but this setting allows you to put external sources for modules in your VSC client's settings.json file. – Mason Ritchason Commented Nov 21, 2024 at 20:42
Add a comment  | 

1 Answer 1

Reset to default 2

Autocomplete and IntelliSense are provided for all files within the current working folder in VSCode. They're also available for Python packages that are installed in standard locations.

To enable IntelliSense for packages that are installed in non-standard locations, add those locations to the python.autoComplete.extraPaths collection in your settings.json file.

Ref:https://code.visualstudio.com/docs/python/settings-reference#_autocomplete-settings

本文标签: pythonVSCode Add custom autocomplete to known external classesStack Overflow