October 22, 2024
Chicago 12, Melborne City, USA
python

devcontainer: pylance issue


I have the following folder structure

workspace
│   docker-compose.yml
│   Dockerfile
│
├───.devcontainer
│       devcontainer.json
│
└───app
        __init__.py
        main.py

Dockerfile

FROM python:3.9 

docker-compose.yml

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: app
    environment:
      - PYTHONDONTWRITEBYTECODE=1
    volumes:
      - .:/workspace:cached
    command: sleep infinity

devcontainer.json

{
    "name": "app",
    "dockerComposeFile": "../docker-compose.yml",
    "service": "app",
    "workspaceFolder": "/workspace",
    "customizations": {
        "vscode": {
            "extensions": [
            "ms-python.python",
        "charliermarsh.ruff"
        ]
        }
    }
}

If i try to create a new file sub.py under /app and import it from main.py, auto complete doesn’t work

main.py

from app.sub import *    #I get an error saying Import "app.sub" could not be resolvedPylance[reportMissingImports]

Now if I try to reload the the window, import works as expected.

Does anyone know how I can resolve this?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video