skip to Main Content

I have a VS Code (1.83.1) workspace with multiple folders each containing a python package.

-Package1
--ClassA
-Package2
--ClassB

Package1 and Package2 are both packages I’m developing, but Package2 uses the modules in Package1, among other modules. I have installed Package1 in the virtual environment for Package2 with the following command (I added the editable_mode recently to see if it helped…it did not).

pip install -e c:\users\user\GitLab\modules --config-settings editable_mode=strict

If I’m editing within ClassB, then open ClassA, the Intellisense or syntax highlighting (language server?) immediately stops working and all text goes white for that ClassA package. The functionality seems to continue in Package2 just fine.

If I restart VS Code, everything works until I do the same above actions. If I only ever view Package1 and ClassA or other Package1 entities, it continues to work. It only seems to cause grief for Package1.

I tried looking at the Extension Logs for the Python language server and added the following to my User settings.json to increase verbosity, but nothing jumps out as an error like I was hoping:

"python.analysis.logLevel": "Trace",

imports "working"

enter image description here

imports "broken"

enter image description here

If I restart the Python language server:
enter image description here
functionality is restored

I noticed that if I use "python.analysis.extraPaths" in Package2, pointing to the directory for Package1, it causes code in Package1 to stop being parsed properly. It seems like perhaps there’s a collision of name spaces or something similar.

I created a new workspace, and only added Package1 and Package2 directories as roots. When I did that, I noticed that when I CTRL+clicked a Package1 entity from Package2, it took me to the build sub-folder that was generated during the editable pip install:

C:Usersusergitlabmodulesbuild__editable__.modules-0.0.5-py3-none-any...

and the text was unparsed as I saw earlier in my other workspace.

Back in my original workspace, I still see the issue. If I manually open the proper location from the file explorer, the parsing takes place as expected.

2

Answers


  1. Chosen as BEST ANSWER

    I found out my primary issue seems related to multi-root VS code workspace. When I constructed a workspace referencing a single root folder, which contained all the packages I was editing, ALL issues around linking, finding, and editing packages worked immediately.

    The tip for using "python.analysis.extraPaths" in the root location .vscode/settings.json does avoid the issue of needing to use editable installs for packages in development.

    As a result, my solution is similar to these existing articles and considerations:

    Configure Python Path for multiple folders in one Visual Studio Code workspace file

    https://code.visualstudio.com/docs/editor/multi-root-workspaces


  2. You can try to add the following codes to your settings.json to gain intellisense:

      "python.analysis.extraPaths": [
        "path/to/your/classA"
      ],
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search