Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

VS Code won't make import suggestions for my Python library

I have made a Python library whose tree directory structure looks like

lorentz_enrichment
├── __init__.py
│ └── lorentz_enricher.cpython-312.pyc
├── configs
│ ├── __init__.py
│ │ ├── logger.cpython-312.pyc
│ │ ├── s3.cpython-312.pyc
│ │ ├── settings.cpython-312.pyc
│ │ └── tqdm_handler.cpython-312.pyc
│ ├── logger.py
│ ├── s3.py
│ ├── settings.py
│ └── tqdm_handler.py
├── db
│ ├── __init__.py
...
├── lorentz_enricher.py
├── main.py
...
├── py.typed
...
32 directories, 157 files

This is what my __init__.py contains:

import logging
from typing import TYPE_CHECKING
if TYPE_CHECKING:
 from .configs.settings import LorentzEnricherSettingsProvider
 from .db.mongo.claim_rules_repository import ClaimRulesRepository
 from .db.mongo.lorentz_claims_repository import LorentzClaimsRepository
 from .db.mongo.mongo_base_repository import MongoBaseRepository
 from .db.mongo.queue_messages_repository import QueueMessagesRepository
 ...
from .configs.settings import LorentzEnricherSettingsProvider
from .db.mongo.claim_rules_repository import ClaimRulesRepository
from .db.mongo.lorentz_claims_repository import LorentzClaimsRepository
from .db.mongo.mongo_base_repository import MongoBaseRepository
from .db.mongo.queue_messages_repository import QueueMessagesRepository
...
logging.getLogger(__name__).addHandler(logging.NullHandler())
__all__ = [
 'LorentzEnricher',
 'LorentzEnricherSettingsProvider',
 ...
]
def __dir__() -> list[str]:
 return list(__all__)

Everything under TYPE_CHECKING is imported outside too. And this is my pyproject.toml:

[tool.poetry]
name = "lorentz-enrichment"
version = "0.27.0-b5"
description = "Tools to enrich Lorentz claims with meteorological data"
authors = ["asant <***@***.eu>"]
readme = "README.md"
packages = [{ include = "lorentz_enrichment" }]
[tool.poetry.dependencies]
python = "^3.12"
...
[tool.poetry.group.dev.dependencies]
black = "24.10.0"
ruff = "0.11.11"
...
[tool.mypy]
exclude = [".venv"]
ignore_missing_imports = true
enable_error_code = "possibly-undefined"
disable_error_code = ["import-untyped", "override"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

In my microservice the imports like from lorentz_enrichment import LorentzEnricher works correctly, however when in my code I type some classes like LorentzEnricher() without importing it first, VS Code won't suggest the import like it does for pydantic BaseModel for example.

What am I missing here?

Answer*

Draft saved
Draft discarded
Cancel
4
  • what the path should be? Consider that I am publishing my library on an internal nexus. Why do I need to perform extra steps whereas libraries like pydantic, s3fs, pandas require no additional steps to work properly with autosuggestions? Commented Sep 25, 2025 at 12:57
  • @asant-leitha The path should be the root of wherever your module is actually being installed (i.e. <install path>/lorentz_enrichment/. I suspect that it's ending up somewhere VS Code "can't see" out of the box. FWIW, if the install ends up somewhere typical, e.g. site-packages, it should pick up automatically - but sometimes VS Code is finicky. Commented Sep 25, 2025 at 13:05
  • Yes, it is installed in the site-packages of the venv folder, like any other library, what is not working for me? Commented Sep 25, 2025 at 13:07
  • I'm not sure specifically why it isn't working for you (nothing stands out to me in the information you've provided), but I know I've had to do this for my own packages in the past in order to get VS Code to cooperate. Apologies, I know it's not the most satisfying answer. (Also, StackOverflow won't let me reply to your second comment, so I'm being forced to reply here) Commented Sep 25, 2025 at 13:15

lang-py

AltStyle によって変換されたページ (->オリジナル) /