4

Overview

I have a VSCode workspace which contains two directories. In one is my main application, in another is a common package used by this application and a couple of others.
  # main-app.code-workspace
  "folders": [
    {
      "path": "."
    },
    {
      "path": "../common/shared_package"
    }
  ],

I am able to import classes from the shared package if I manually type out the import string (from shared_package.utils.clock import SuperClock), but VSCode's quick-fix isn't offering any help with this.

Image showing that quick fix does not offer suggestion when I type out SuperClock

  1. Imports from other dependencies typically work with quick-fix (eg if I type trio I get an Auto-Import suggestion from VS Code)
  2. Imports from within main-app also work fine with quick-fix
  3. Manually typing out the import to pull in classes from shared_package is fine
  4. Quick fix does not work with shared_package classes

Additional Info

  1. This is a Python project which uses Poetry for dependency management
  2. my pyproject.toml file includes this line
[tool.poetry.dependencies]
shared-hub-be = { path = "../common/shared_package", develop = true }
  1. I think it might be a red herring, but I am seeing this error (and only this error) in output when I open VSCode
2024-08-01 10:50:48.793 [error] Error: spawn pixi ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn pixi',
  path: 'pixi',
  spawnargs: [ '--version' ]
}
  1. "python.languageServer": "Pylance" is set in workspace file

What have I tried so far

I did what any of us would do and spent 6 months manually typing out the import statements.

Beyond that I tried some back and forth with ChatGPT - it suggested

  1. Add the following to both my VSCode settings file and the Workspace settings file.
"python.analysis.extraPaths": ["../common/shared_package"]
  1. Update PYTHONPATH to include /absolute/path/to/common/shared_package
  2. Try removing develop=true and then rerunning poetry install

None of this stuff helped and has now been reverted.

6
  • Hello, under the same workspace, you can try using the relative import module. I was very happy to see you say that the problem has now been restored. If you can, you can edit the answer to the workaround and post it. I think this is helpful for other members who are having similar issues, thank you very much. Commented Aug 2, 2024 at 6:40
  • Hey Jeanneli Sorry, to be clear this issue has not been resolved. What do you mean by using the relative import module? Commented Aug 2, 2024 at 13:38
  • 1
    if shared_package can be installed by pip, and you have a virtual environment, you can install it in editable mode with pip -e. Commented Aug 4, 2024 at 16:39
  • Sorry, the relative import is based on the location of the current module. Use something like from .import shared_package.utils.clock. Does using relative import like this solve the problem? You need to make sure that the environment of the interpreter you are currently selecting has shared_package installed. Commented Aug 5, 2024 at 7:15
  • @Jeanneli, again just clarifying that I can import from shared_package with from shared_package.utils.clock import SuperClock. Manually typing it is fine and always has been. My problem is that quick fix is seemingly not aware of the package and so does not suggest importing from it when a class isn't found. @darda, I'm using poetry which installs packages as editable when develop = true is set in pyproject.toml as it is here. See: github.com/python-poetry/poetry/issues/… Commented Aug 5, 2024 at 18:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.