Pylance has issues when running applications in a dev container. Below is my current dev container json plus my system details:
// For format details, see https://aka.ms/devcontainer.json
// For config options, see https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
"name": "Dev-Container",
"dockerComposeFile": "../compose.yml",
"service": "xxxxxxx",
"workspaceFolder": "/usr/src/app",
// An array of services that should be started and stopped.
"runServices": ["cloudsql-proxy", "xxxxxx"],
// runs `/bin/sh -c "while sleep 1000; do :; done" ` to keep container running instead of default command.
"overrideCommand": true,
// Features to add to the dev container. More info: https://containers.dev/features
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"username": "none"
}
},
// add the workspace folder to the global git config (need to do this for now. probably a better solution exists)
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
// install node and npm install
"postCreateCommand": [
"bash",
"-c",
"pip install pylint-django debugpy && curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && sudo apt-get install -y nodejs && cd src/static && npm install"
],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
/* Python Editor Settings */
"python.defaultInterpreterPath": "/usr/local/bin/python",
"[python]": {
"editor.formatOnType": true,
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"autoDocstring.docstringFormat": "one-line-sphinx",
/* Python Test Settings */
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
/* Python Language Server Settings */
"python.analysis.autoImportCompletions": true,
"python.analysis.completeFunctionParens": true,
"python.analysis.autoFormatStrings": true,
"python.analysis.packageIndexDepths": [
{
"name": "django",
"depth": 5
}
],
/* PyLint Settings */
"pylint.enabled": true,
"pylint.args": [
"--disable=C0114,C0115,R0903",
"--load-plugins",
"pylint_django",
"--django-settings-module",
"xxxxxx.settings.dev"
],
"editor.quickSuggestions": {
"strings": "on"
},
"files.insertFinalNewline": true,
"files.associations": {
"*.css": "tailwindcss",
"**/*.html": "html",
"**/templates/**/*.html": "django-html",
"**/templates/**/*": "django-txt"
},
"launch": {
"configurations": [
{
"name": "(Debug): Server",
"type": "debugpy",
"request": "launch",
"args": ["runserver", "0.0.0.0:8000"],
"django": true,
"justMyCode": false,
"program": "${workspaceFolder}/src/manage.py"
}
]
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "(Run): Server",
"type": "process",
"command": "python",
"args": ["${workspaceFolder}/src/manage.py", "runserver", "0.0.0.0:8000"]
}
]
}
},
"extensions": [
// Python
"ms-python.python",
"ms-python.pylint",
"ms-python.vscode-pylance",
"ms-python.debugpy",
"ms-python.black-formatter",
"njpwerner.autodocstring",
// Django
"batisteo.vscode-django",
// Docker
"ms-azuretools.vscode-docker",
// Tailwind and AlpineJS
"bradlc.vscode-tailwindcss",
"adrianwilczynski.alpine-js-intellisense",
// Markdown
"shd101wyy.markdown-preview-enhanced"
]
}
}
}
Container starts up perfect except issues with Pylance. In the full dev container log, I don’t see any issues with pylance downloading (my dev container logs contains env variables so can’t post now, will have to recreate problem in a demo project and post logs if yall don’t see the issue easily)
When I got to Output → Python Language Server. I get the following:
2024-10-20 17:19:13.451 [info] [Info - 5:19:13 PM] Pyright language server 1.1.325 starting
2024-10-20 17:19:13.452 [info] [Info - 5:19:13 PM] Server root directory: /root/.cursor-server/extensions/anysphere.pyright-1.1.327-universal/dist
2024-10-20 17:19:13.474 [info] [Info - 5:19:13 PM] Starting service instance "app"
2024-10-20 17:19:13.660 [info] [Info - 5:19:13 PM] Setting pythonPath for service "app": "/usr/local/bin/python"
2024-10-20 17:19:13.683 [info] [Info - 5:19:13 PM] Loading pyproject.toml file at /usr/src/app/pyproject.toml
2024-10-20 17:19:13.710 [info] [Info - 5:19:13 PM] Pyproject file "/usr/src/app/pyproject.toml" has no "[tool.pyright]" section.
2024-10-20 17:19:13.712 [info] [Warn - 5:19:13 PM] stubPath /usr/src/app/typings is not a valid directory.
2024-10-20 17:19:13.808 [info] [Info - 5:19:13 PM] Assuming Python version 3.11
2024-10-20 17:19:14.320 [info] [Info - 5:19:14 PM] Found 707 source files
It looks like Pyright is starting. Nothing with Pylance (its not installed for some reason as well). So I manually install Pylance everytime the container is rebuilt as of right now. Logs continued below:
Logs of Manual Install
[2024-10-20T17:23:35.222Z] [17:23:35] Started downloading extension: ms-python.vscode-pylance 2024.8.1 file:///root/.cursor-server/extensionsCache/cursor-ms-python.vscode-pylance-2024.8.1
[2024-10-20T17:23:36.939Z] [17:23:36] Extension signature verification is not done: ms-python.vscode-pylance
[2024-10-20T17:23:42.568Z] [17:23:42] Extracted extension to file:///root/.cursor-server/extensions/ms-python.vscode-pylance-2024.8.1: ms-python.vscode-pylance
[2024-10-20T17:23:42.580Z] [17:23:42] Renamed to /root/.cursor-server/extensions/ms-python.vscode-pylance-2024.8.1
[2024-10-20T17:23:42.605Z] [17:23:42] Extension installed successfully: ms-python.vscode-pylance file:///root/.cursor-server/extensions/extensions.json
Python Language Server Output
2024-10-20 17:23:42.727 [info] [Info - 5:23:42 PM] Setting pythonPath for service "app": "/usr/local/bin/python"
2024-10-20 17:23:42.728 [info] [Info - 5:23:42 PM] Loading pyproject.toml file at /usr/src/app/pyproject.toml
2024-10-20 17:23:42.730 [info] [Info - 5:23:42 PM] Pyproject file "/usr/src/app/pyproject.toml" has no "[tool.pyright]" section.
2024-10-20 17:23:42.736 [info] [Warn - 5:23:42 PM] stubPath /usr/src/app/typings is not a valid directory.
2024-10-20 17:23:42.736 [info] [Info - 5:23:42 PM] Assuming Python version 3.11
2024-10-20 17:23:42.848 [info] [Info - 5:23:42 PM] Found 707 source files
It looks like Pyright again is doing stuff but no Pylance.
So, it also requires a reload window action. I usually refresh the extensions as well when doing this. Then I will see this:
2024-10-20 17:26:38.131 [info] (Client) Pylance async client (2024.8.1) started with python extension (2024.12.3)
2024-10-20 17:26:38.633 [info] [Info - 5:26:38 PM] (3761) Pylance language server 2024.8.1 (pyright version 1.1.373, commit ee424479) starting
2024-10-20 17:26:38.633 [info] [Info - 5:26:38 PM] (3761) Server root directory: file:///root/.cursor-server/extensions/ms-python.vscode-pylance-2024.8.1/dist
2024-10-20 17:26:38.641 [info] [Info - 5:26:38 PM] (3761) Starting service instance "app"
2024-10-20 17:26:38.687 [info] [Info - 5:26:38 PM] (3761) Setting pythonPath for service "app": "/usr/local/bin/python"
2024-10-20 17:26:38.688 [info] [Info - 5:26:38 PM] (3761) Setting environmentName for service "app": "3.11.10 (global)"
2024-10-20 17:26:38.688 [info] [Info - 5:26:38 PM] (3761) Loading pyproject.toml file at /usr/src/app/pyproject.toml
2024-10-20 17:26:38.693 [info] [Info - 5:26:38 PM] (3761) Pyproject file "/usr/src/app/pyproject.toml" has no "[tool.pyright]" section.
2024-10-20 17:26:38.693 [info] [Info - 5:26:38 PM] (3761) No include entries specified; assuming /usr/src/app
2024-10-20 17:26:38.694 [info] [Info - 5:26:38 PM] (3761) Auto-excluding **/node_modules
2024-10-20 17:26:38.694 [info] [Info - 5:26:38 PM] (3761) Auto-excluding **/__pycache__
2024-10-20 17:26:38.694 [info] [Info - 5:26:38 PM] (3761) Auto-excluding **/.*
2024-10-20 17:26:38.728 [info] [Info - 5:26:38 PM] (3761) Assuming Python version 3.11.10.final.0
2024-10-20 17:26:38.964 [info] [Info - 5:26:38 PM] (3761) Found 707 source files
2024-10-20 17:26:39.195 [info] [Info - 5:26:39 PM] (3761) Background analysis(1) root directory: file:///root/.cursor-server/extensions/ms-python.vscode-pylance-2024.8.1/dist
2024-10-20 17:26:39.198 [info] [Info - 5:26:39 PM] (3761) Background analysis(1) started
2024-10-20 17:26:49.812 [info] [Info - 5:26:49 PM] (3761) Indexer background runner(2) root directory: file:///root/.cursor-server/extensions/ms-python.vscode-pylance-2024.8.1/dist (index)
2024-10-20 17:26:49.813 [info] [Info - 5:26:49 PM] (3761) Indexing(2) started
2024-10-20 17:26:50.688 [info] [Info - 5:26:50 PM] (3761) scanned(2) 904 files over 1 exec env
2024-10-20 17:26:53.224 [info] [Info - 5:26:53 PM] (3761) [IDX(2)] Long operation: index execution environment file:///usr/src/app (2178ms)
2024-10-20 17:26:53.248 [info] [Info - 5:26:53 PM] (3761) [IDX(2)] Long operation: index packages file:///usr/src/app (2219ms)
2024-10-20 17:26:53.249 [info] [Info - 5:26:53 PM] (3761) indexed(2) 669 files over 1 exec env
2024-10-20 17:26:53.354 [info] [Info - 5:26:53 PM] (3761) Indexing finished(2).
Now Pylance is working.
Edit: Also just figured out that refreshing the extensions will install pylance so I just cut down 1 unnecessary step. But I still need to do refresh extensions and reload window for Pylance to start doing its stuff