Python autocomplete in VS Code not working with external libraries in conda environment
Asked Answered
S

3

10

I have installed several libraries into a conda environment named "foo". I am using Visual Studio Code as my IDE.

Autocomplete works fine for almost all packages, except for the library "openmesh" (see below): Autocomplete with openmesh

Autcomplete with a different library

I have selected the correct python interpreter in VS Code: Interpreter

As confirmed in the bottom left corner.

Version

Furthermore, I have tried to add it to the autocomplete path in the settings of VS Code, however, there was no change, even after relaunching.

Extra Paths

Autocomplete works fine with PyCharm, as seen here: Pycharm

What am I doing wrong?

Scandura answered 18/1, 2022 at 20:4 Comment(7)
Ctrl+Click on the openmesh, can you get into the module? openmesh has not been colored, it's a little weird.Leake
When you run ~/miniconda3/envs/foo/bin/pip list in a terminal, does it contain openmesh? When you open a terminal in VS code, does the prompt show your venv prefix?Anaphase
@Leake I cannot go to Declaration, Definition or Type Definition. It always says "Declaration not found for 'om'".Scandura
@Anaphase it does it contain openmesh. In VS code, the prompt shows me the venv prefix (foo), i.e. the Python Interpreter I selected.Scandura
@tlk13, were you able to figure out a solution to this? I'm facing a similar issue with AWS CDK library. I've tried re-installing VSCode with no avail.Wey
Hi @m01010011, very cool that you found my initial issue after all this time! Unfortunately i was not able to solve it. basically i just switched back and forth between documentation and VS Code until i had it memorised :(. if you find a solution, do let me know!Scandura
This may be the same problem I reported to Microsoft some time ago -- no intellisense for binary Python modules. If so, they acknowledged the problem but did not want to prioritise it. This is a shame because otherwise VS Code is extremely capable across multiple languages.Twofaced
T
2

Had a similar problem, auto-completion was not working with python.

The following worked for me:

Use the keyboard shortcut to open the command palette:

Ctrl + Shift + P

and search for:

Python: Restart Language Server

Hit enter. Now give it another try.

Terribly answered 9/1, 2023 at 21:9 Comment(0)
K
1

https://code.visualstudio.com/docs/python/environments : There are two types of environments that you can create for your workspace: virtual and conda environments.

you have to work into a workspace

Krongold answered 10/4, 2023 at 11:55 Comment(0)
S
0

Open your Terminal, activate your environment (i.e. conda activate foo), and then launch VS Code from within terminal in which you activated your environment (i.e. code . or code /path/to/directory). This worked for me.

If you are on Windows you can follow this link

Selector answered 17/7, 2023 at 3:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.