Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python environments not detected/found in devcontainer on WSL 2 #24071

Open
mhabibav opened this issue Sep 7, 2024 · 21 comments
Open

Python environments not detected/found in devcontainer on WSL 2 #24071

mhabibav opened this issue Sep 7, 2024 · 21 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team

Comments

@mhabibav
Copy link

mhabibav commented Sep 7, 2024

Type: Bug

Behaviour

I have a Windows machine where VS Code is installed. The machine has WSL 2 (Ubuntu 22.04) where docker is installed.

I can successfully connect to WSL from my VS Code desktop. I have a repo inside WSL with a devcontainer. I can build and use the container normally except for one frustrating thing. Any Python environment created inside the container using Poetry, is not detected by the "Select Interpreter" button. No matter how many times I press the refresh button (in the select interpreter window) or reopen the container; the environments never show up.

Here's a screenshot of the select interpreter window:
image

Here's what's inside ~/.cache/pypoetry/virtualenvs:
image

Here's the output of the Python extension after pressing refresh:
image

Steps to reproduce:

  1. Have WSL 2 with Docker installed inside WSL
  2. Reopen folder in devcontainer
  3. Create a Poetry environment by any means
  4. Open a Python file and press Select Interpreter

Expected behavior: poetry env is automatically detected and is selectable
Current behavior: Environment doesn't show up

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

Extension version: 2024.14.0
VS Code version: Code 1.93.0 (4849ca9bdf9666755eb463db297b69e5385090e3, 2024-09-04T13:02:38.431Z)
OS version: Windows_NT x64 10.0.22631
Modes:
Remote OS version: Linux x64 5.15.146.1-microsoft-standard-WSL2

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.3
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
  • Value of the python.languageServer setting: Pylance
User Settings


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
Auto Close Tag formulahendry.auto-close-tag 0.5.15
Auto Rename Tag formulahendry.auto-rename-tag 0.1.10
autoDocstring - Python Docstring Generator njpwerner.autodocstring 0.6.1
Bruno bruno-api-client.bruno 3.1.0
Conventional Commits vivaxy.vscode-conventional-commits 1.26.0
DotENV mikestead.dotenv 1.0.1
ESLint dbaeumer.vscode-eslint 3.0.10
Even Better TOML tamasfe.even-better-toml 0.19.2
Gemini Code Assist + Google Cloud Code googlecloudtools.cloudcode 2.16.7
Git Graph mhutchie.git-graph 1.30.0
Git History donjayamanne.githistory 0.6.20
HashiCorp Terraform hashicorp.terraform 2.32.3
Import Cost wix.vscode-import-cost 3.3.0
IntelliCode API Usage Examples VisualStudioExptTeam.intellicode-api-usage-examples 0.2.8
JavaScript Debugger ms-vscode.js-debug 1.93.0
Jupyter ms-toolsai.jupyter 2024.8.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.19
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Live Server ritwickdey.LiveServer 5.7.9
Markdown Preview Enhanced shd101wyy.markdown-preview-enhanced 0.8.13
Markdown Preview Mermaid Support bierner.markdown-mermaid 1.24.0
npm Intellisense christian-kohler.npm-intellisense 1.4.5
OpenAPI (Swagger) Editor 42Crunch.vscode-openapi 4.28.1
PDF Viewer mathematic.vscode-pdf 0.0.6
Prettier - Code formatter esbenp.prettier-vscode 11.0.0
Pylance ms-python.vscode-pylance 2024.8.2
Python ms-python.python 2024.14.0
Python Debugger ms-python.debugpy 2024.10.0
Python Environment Manager donjayamanne.python-environment-manager 1.2.4
Rainbow CSV mechatroner.rainbow-csv 3.12.0
Ruff charliermarsh.ruff 2024.44.0
Simple React Snippets burkeholland.simple-react-snippets 1.2.8
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
XML redhat.vscode-xml 0.27.1
YAML redhat.vscode-yaml 1.15.0
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 7, 2024
@mhabibav
Copy link
Author

mhabibav commented Sep 7, 2024

Here's the output of the Python Extension:

Python extension output
2024-09-07 13:03:30.766 [info] Python interpreter path: /bin/python3
2024-09-07 13:03:30.899 [info] > pyenv which python
2024-09-07 13:03:30.899 [info] cwd: .
2024-09-07 13:03:31.418 [info] > conda info --json
2024-09-07 13:03:32.370 [info] Starting Pylance language server.
2024-09-07 13:03:41.321 [info] Starting Environment refresh
2024-09-07 13:03:41.321 [info] Searching for interpreters in posix paths locator
2024-09-07 13:03:41.323 [info] Searching for pyenv environments
2024-09-07 13:03:41.323 [info] Searching for conda environments
2024-09-07 13:03:41.323 [info] Searching for global virtual environments
2024-09-07 13:03:41.323 [info] Searching for custom virtual environments
2024-09-07 13:03:41.333 [info] > pixi --version
2024-09-07 13:03:41.333 [info] > hatch env show --json
2024-09-07 13:03:41.333 [info] cwd: .
2024-09-07 13:03:41.336 [info] pyenv is not installed
2024-09-07 13:03:41.336 [info] Finished searching for pyenv environments: 14 milliseconds
2024-09-07 13:03:41.336 [info] Finished searching for custom virtual envs: 13 milliseconds
2024-09-07 13:03:41.337 [info] Finished searching for global virtual envs: 14 milliseconds
2024-09-07 13:03:41.351 [info] Found: /bin/python3 --> /bin/python3.12
2024-09-07 13:03:41.352 [info] Found: /bin/python3.12 --> /bin/python3.12
2024-09-07 13:03:41.358 [info] > C:\Users\mhabiba\AppData\Local\Programs\Python\Python312\python.exe -I ~/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/interpreterInfo.py
2024-09-07 13:03:41.368 [error] Error: Command failed: C:\Users\mhabiba\AppData\Local\Programs\Python\Python312\python.exe -I /home/vscode/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py /home/vscode/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/interpreterInfo.py
/bin/sh: 1: C:UsersmhabibaAppDataLocalProgramsPythonPython312python.exe: not found

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at ChildProcess.exithandler (node:child_process:422:12)
    at ChildProcess.emit (node:events:531:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Pipe.<anonymous> (node:net:338:12) {
  code: 127,
  killed: false,
  signal: null,
  cmd: 'C:\\Users\\mhabiba\\AppData\\Local\\Programs\\Python\\Python312\\python.exe -I /home/vscode/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py /home/vscode/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/interpreterInfo.py'
}
2024-09-07 13:03:41.371 [info] Found: /usr/bin/python3 --> /usr/bin/python3.12
2024-09-07 13:03:41.371 [info] Found: /usr/bin/python3.12 --> /usr/bin/python3.12
2024-09-07 13:03:41.387 [info] Finished searching for interpreters in posix paths locator: 64 milliseconds
2024-09-07 13:03:41.387 [info] > /bin/python3 -I ~/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/interpreterInfo.py
2024-09-07 13:03:41.399 [info] > /usr/bin/python3 -I ~/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/interpreterInfo.py
2024-09-07 13:03:41.399 [info] Environments refresh paths discovered (event): 80 milliseconds
2024-09-07 13:03:41.399 [info] Environments refresh paths discovered: 81 milliseconds
2024-09-07 13:03:43.375 [info] > C:\Users\mhabiba\AppData\Local\Programs\Python\Python312\python.exe -I ~/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/interpreterInfo.py
2024-09-07 13:03:43.378 [error] Error: Command failed: C:\Users\mhabiba\AppData\Local\Programs\Python\Python312\python.exe -I /home/vscode/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py /home/vscode/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/interpreterInfo.py
/bin/sh: 1: C:UsersmhabibaAppDataLocalProgramsPythonPython312python.exe: not found

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at ChildProcess.exithandler (node:child_process:422:12)
    at ChildProcess.emit (node:events:531:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Pipe.<anonymous> (node:net:338:12) {
  code: 127,
  killed: false,
  signal: null,
  cmd: 'C:\\Users\\mhabiba\\AppData\\Local\\Programs\\Python\\Python312\\python.exe -I /home/vscode/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py /home/vscode/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/interpreterInfo.py'
}
2024-09-07 13:03:43.418 [info] Environments refresh finished (event): 2100 milliseconds
2024-09-07 13:03:43.428 [info] Environment refresh took 2111 milliseconds
2024-09-07 13:03:47.621 [info] Starting Environment refresh
2024-09-07 13:03:47.621 [info] Searching for interpreters in posix paths locator
2024-09-07 13:03:47.622 [info] Searching for pyenv environments
2024-09-07 13:03:47.622 [info] Searching for conda environments
2024-09-07 13:03:47.622 [info] Searching for global virtual environments
2024-09-07 13:03:47.622 [info] Searching for custom virtual environments
2024-09-07 13:03:47.623 [info] pyenv is not installed
2024-09-07 13:03:47.623 [info] Finished searching for pyenv environments: 1 milliseconds
2024-09-07 13:03:47.624 [info] Finished searching for custom virtual envs: 2 milliseconds
2024-09-07 13:03:47.625 [info] Finished searching for global virtual envs: 3 milliseconds
2024-09-07 13:03:47.628 [info] Found: /bin/python3 --> /bin/python3.12
2024-09-07 13:03:47.628 [info] Found: /bin/python3.12 --> /bin/python3.12
2024-09-07 13:03:47.634 [info] Found: /usr/bin/python3 --> /usr/bin/python3.12
2024-09-07 13:03:47.634 [info] Found: /usr/bin/python3.12 --> /usr/bin/python3.12
2024-09-07 13:03:47.649 [info] Finished searching for interpreters in posix paths locator: 28 milliseconds
2024-09-07 13:03:47.654 [info] Environments refresh paths discovered (event): 34 milliseconds
2024-09-07 13:03:47.654 [info] Environments refresh finished (event): 34 milliseconds
2024-09-07 13:03:47.654 [info] Environments refresh paths discovered: 34 milliseconds
2024-09-07 13:03:47.658 [info] Environment refresh took 37 milliseconds

I noticed it had 2 errors and both apparently are due to the extension mixing up Windows and Unix paths?

@mhabibav
Copy link
Author

mhabibav commented Sep 7, 2024

The 2 errors turned out to be because I had set python.defaultInterpreterPath in the user settings in Windows. I removed it and indeed the error in the output is gone. But the first issue remains: environments are still not detected.

@karthiknadig
Copy link
Member

@mhabibav We don't know the paths where poetry creates it. You can try one of two things:
[Option 1]: Set python.locator to native and see if it helps.
[Option 2]: Set python.venvFolder setting to point to the poetry envs path ~/.cache/pypoetry/virtualenvs.

In both cases you can set it and then do refresh by running Python: Clear cache and reload

@karthiknadig karthiknadig self-assigned this Sep 9, 2024
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-environments Features relating to handling interpreter environments labels Sep 9, 2024
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Sep 9, 2024
@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Sep 11, 2024
@mhabibav
Copy link
Author

Hello @karthiknadig thanks for your reply!

We don't know the paths where poetry creates it.

I haven't changed any of Poetry's configurations so I guess all environments are created in ~/.cache/pypoetry/virtualenvs.

[Option 1]: Set python.locator to native and see if it helps.

Still not showing up, here's a screenshot from the logs.
image

[Option 2]: Set python.venvFolder setting to point to the poetry envs path ~/.cache/pypoetry/virtualenvs.

Also not showing up. Logs:
image

@karthiknadig
Copy link
Member

Can you share your settings.json?

@DonJayamanne is the ~/.cache/pypoetry/virtualenvs searched by pet?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Sep 11, 2024
@DonJayamanne
Copy link

I do not hardcode that path in pet,
We try to find poetry and read the configuration files and then go from there.
I can add some logging to see why we're not getting those.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Sep 12, 2024
@DonJayamanne
Copy link

@mhabibav

Reopen folder in devcontainer

Would it be possible to share this dev container (i.e. just the docker file or the base image used)
Basically would like to test this at our end with the exact same dev container (poetry and the like).
If there are some additional scripts required to install/setup the poetry/python envs, please do share those in the docker file.

@DonJayamanne DonJayamanne added the info-needed Issue requires more information from poster label Sep 12, 2024
@mhabibav
Copy link
Author

Can you share your settings.json?

User settings.json
{
    ////////////////////////////////////////////////////////////////////////////
    // Window
    ////////////////////////////////////////////////////////////////////////////
    "window.restoreWindows": "none",
    "window.zoomLevel": 0,
    
    
    ////////////////////////////////////////////////////////////////////////////
    // Workbench
    ////////////////////////////////////////////////////////////////////////////
    "workbench.editor.restoreViewState": false,
    "workbench.tree.enableStickyScroll": true,
    "workbench.editor.showTabs": "multiple",
    "workbench.colorTheme": "Noctis Obscuro",
    "workbench.sideBar.location": "right",
    "workbench.iconTheme": "vscode-icons",
    "workbench.editor.alwaysShowEditorActions": true,


    ////////////////////////////////////////////////////////////////////////////
    // Explorer
    ////////////////////////////////////////////////////////////////////////////
    "explorer.compactFolders": false,


    ////////////////////////////////////////////////////////////////////////////
    // Editor
    ////////////////////////////////////////////////////////////////////////////
    "editor.fontLigatures": true,
    "editor.fontFamily": "'Cascadia Code', 'Fira Code', 'Source Code Pro', Consolas, 'Courier New', monospace",
    "editor.fontSize": 14,
    "editor.inlineSuggest.enabled": true,
    "editor.stickyScroll.enabled": true,
    "editor.rulers": [
        80,
        100,
        120,
    ],


    ////////////////////////////////////////////////////////////////////////////
    // Terminal
    ////////////////////////////////////////////////////////////////////////////
    "terminal.integrated.scrollback": 10000,
    "terminal.integrated.defaultProfile.windows": "PowerShell",
    "terminal.integrated.fontFamily": "'Cascadia Code NF', 'Fira Code', 'Source Code Pro', Consolas, 'Courier New', monospace",


    ////////////////////////////////////////////////////////////////////////////
    // Language
    ////////////////////////////////////////////////////////////////////////////
    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.formatOnType": true,
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        }
    },
    // "[cpp]": {
    //     "editor.defaultFormatter": "ms-vscode.cpptools"
    // },


    ////////////////////////////////////////////////////////////////////////////
    // Extension
    ////////////////////////////////////////////////////////////////////////////
    //      Python
    // "python.languageServer": "Pylance",
    "python.locator": "native",
    "python.analysis.fixAll": [
        "source.unusedImports"
    ],
    "python.venvFolders": [
        "~/.cache/pypoetry/virtualenvs"
    ],
    "python.analysis.inlayHints.functionReturnTypes": true,
    "debugpy.debugJustMyCode": false,
    "jupyter.debugJustMyCode": false,
    //      Red Hat
    "redhat.telemetry.enabled": false,
    //      icons
    "vsicons.dontShowNewVersionMessage": true,
    //      notebook
    "notebook.lineNumbers": "on",


    ////////////////////////////////////////////////////////////////////////////
    // Other
    ////////////////////////////////////////////////////////////////////////////
    "telemetry.telemetryLevel": "off",
    "git.openRepositoryInParentFolders": "never",
    
}
devcontainer settings.json
{
    "terraform.languageServer.enable": true,
    "terraform.languageServer.args": [
        "serve"
    ],
    "azureTerraform.terminal": "integrated",
    "terminal.integrated.defaultProfile.linux": "zsh",
    "extensions.autoUpdate": true,
    "dev.containers.workspaceMountConsistency": "consistent",
    "telemetry.telemetryLevel": "off",
    "redhat.telemetry.enabled": false,
    "cloudcode.enableTelemetry": false,
    "files.associations": {
        ".env*": "dotenv"
    },
    "conventionalCommits.autoCommit": false,
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        }
    },
    "notebook.formatOnSave.enabled": true,
    "notebook.codeActionsOnSave": {
        "source.organizeImports": "explicit"
    },
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "[yaml]": {
        "editor.autoIndent": "full"
    },
}

Would it be possible to share this dev container

devcontainer.json
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
    "name": "devcontainer name",
    // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
    "image": "mcr.microsoft.com/devcontainers/base:noble",
    // Features to add to the dev container. More info: https://containers.dev/features.
    "features": {
        "ghcr.io/devcontainers/features/common-utils:2": {},
        "ghcr.io/devcontainers/features/github-cli:1": {},
        "ghcr.io/devcontainers-contrib/features/copier:7": {},
        "ghcr.io/devcontainers-contrib/features/poetry:2": {},
        "ghcr.io/devcontainers-contrib/features/ruff:1": {},
        "ghcr.io/devcontainers/features/node:1": {},
        "ghcr.io/devcontainers/features/docker-in-docker:2": {},
        "ghcr.io/dhoeric/features/act:1": {},
        "ghcr.io/dhoeric/features/google-cloud-cli:1": {
            "installGkeGcloudAuthPlugin": true
        },
        "ghcr.io/devcontainers-contrib/features/jfrog-cli:1": {},
        "ghcr.io/devcontainers/features/terraform:1": {
            "version": "1.5.7"
        }
    },
    // Configure tool-specific properties.
    "customizations": {
        "vscode": {
            "extensions": [
                // AI Stuff
                "googlecloudtools.cloudcode",
                "VisualStudioExptTeam.intellicode-api-usage-examples",
                // Git Stuff
                "mhutchie.git-graph",
                "donjayamanne.githistory",
                "vivaxy.vscode-conventional-commits",
                // Python Stuff
                "ms-python.python",
                "ms-toolsai.jupyter",
                "charliermarsh.ruff",
                "njpwerner.autodocstring",
                "donjayamanne.python-environment-manager",
                // Generic Stuff
                "ms-azuretools.vscode-docker",
                "hashicorp.terraform",
                "redhat.vscode-xml",
                "redhat.vscode-yaml",
                "tamasfe.even-better-toml",
                "mechatroner.rainbow-csv",
                "mathematic.vscode-pdf",
                "shd101wyy.markdown-preview-enhanced",
                "bierner.markdown-mermaid",
                "mikestead.dotenv",
                "bruno-api-client.bruno",
                "42Crunch.vscode-openapi",
                // Web Stuff
                "dbaeumer.vscode-eslint",
                "esbenp.prettier-vscode",
                "christian-kohler.npm-intellisense",
                "ritwickdey.LiveServer",
                "wix.vscode-import-cost",
                "formulahendry.auto-close-tag",
                "formulahendry.auto-rename-tag",
                "burkeholland.simple-react-snippets",
                // Prevented Stuff
                "-ms-python.autopep8",
                "-ms-azuretools.vscode-azureterraform"
            ],
            "settings": {
                "terminal.integrated.defaultProfile.linux": "zsh",
                "extensions.autoUpdate": true,
                "dev.containers.workspaceMountConsistency": "consistent",
                "telemetry.telemetryLevel": "off",
                "redhat.telemetry.enabled": false,
                "cloudcode.enableTelemetry": false,
                "files.associations": {
                    ".env*": "dotenv"
                },
                "conventionalCommits.autoCommit": false,
                "[python]": {
                    "editor.formatOnSave": true,
                    "editor.defaultFormatter": "charliermarsh.ruff",
                    "editor.codeActionsOnSave": {
                        "source.organizeImports": "explicit"
                    }
                },
                "notebook.formatOnSave.enabled": true,
                "notebook.codeActionsOnSave": {
                    "source.organizeImports": "explicit"
                },
                "[jsonc]": {
                    "editor.defaultFormatter": "vscode.json-language-features"
                },
                "[yaml]": {
                    "editor.autoIndent": "full"
                }
            }
        }
    },
    // Sepcify minimum resource needs
    "hostRequirements": {
        "cpus": 4,
        "memory": "4gb",
        "storage": "32gb",
        "gpu": "optional"
    },
    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [],
    // Use 'onCreateCommand', 'postCreateCommand' to run commands after the container is created.
    "onCreateCommand": {
        "default-apt-packages": "sudo apt update && sudo apt upgrade -y && sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev git git-lfs"
    },
    "postCreateCommand": {
        "git": "git config --global http.sslverify false && git lfs install",
        // "pyenv": "curl https://pyenv.run | bash && echo 'export PYENV_ROOT=\"$HOME/.pyenv\"' | tee -a ~/.zshrc ~/.zprofile ~/.bashrc ~/.profile && echo 'command -v pyenv >/dev/null || export PATH=\"$PYENV_ROOT/bin:$PATH\"' | tee -a ~/.bashrc ~/.profile && echo '[[ -d $PYENV_ROOT/bin ]] && export PATH=\"$PYENV_ROOT/bin:$PATH\"' | tee -a ~/.zshrc ~/.zprofile && echo 'eval \"$(pyenv init -)\"' | tee -a ~/.zshrc ~/.zprofile ~/.bashrc ~/.profile && . ~/.profile && pyenv update && pyenv install 3.12 && pyenv rehash && pyenv global 3.12",
        "poetry": "poetry config virtualenvs.prefer-active-python true"
    }
    // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
    // "remoteUser": "root"
}

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Sep 12, 2024
@DonJayamanne
Copy link

Unfortunately I'm unable to load the container at my end,

12.60 Traceback (most recent call last):
12.60   File "<string>", line 1, in <module>
12.60   File "nanolayer.__main__", line 50, in main
[2024-09-12T20:37:49.235Z] 
12.60   File "typer.main", line 328, in __call__
12.60   File "typer.main", line 311, in __call__
12.60   File "click.core", line 1157, in __call__
12.60   File "typer.core", line 778, in main
12.60   File "typer.core", line 216, in _main
12.60   File "click.core", line 1688, in invoke
12.60   File "click.core", line 1688, in invoke
12.60   File "click.core", line 1434, in invoke
[2024-09-12T20:37:49.235Z] 
12.60   File "click.core", line 783, in invoke
12.60   File "typer.main", line 683, in wrapper
12.60   File "nanolayer.cli.install", line 65, in install_devcontainer_feature
12.60   File "nanolayer.installers.devcontainer_feature.oci_feature_installer", line 131, in install
12.60   File "nanolayer.utils.invoker", line 59, in invoke
12.60 nanolayer.utils.invoker.Invoker.InvokerException: The command 'cd /tmp/tmp664qph_a && chmod +x -R . && _REMOTE_USER="vscode" _REMOTE_USER_HOME="/home/vscode" PACKAGE="poetry" VERSION="latest" INJECTIONS="" INCLUDEDEPS="false" INTERPRETER="" NANOLAYER_VERBOSE="" NANOLAYER_FORCE_CLI_INSTALLATION="" NANOLAYER_PROPAGATE_CLI_LOCATION="1" NANOLAYER_CLI_LOCATION="/tmp/nanolayer-9njECMkBnk/nanolayer" bash  -i  +H ./install.sh' failed. error: Return Code: 100. see logs for details.
12.73 ERROR: Feature "Poetry (via pipx)" (ghcr.io/devcontainers-contrib/features/poetry) failed to install! Look at the documentation at http://github.com/devcontainers-contrib/features/tree/main/sr
[2024-09-12T20:37:49.235Z] c/poetry for help troubleshooting this error.

Will try this on a windows machine, @karthiknadig are you able to test this at your end..

@DonJayamanne
Copy link

@mhabibav Sorry for the radio silence, was on leave for a few weeks.
I've tested this at my end in a dev container and this works as expected.

Please can you

  • Install the latest pre-release version of the Python extension
  • Try to select an interpreter via the command Python: Select Interpeter
  • Open the Python Locator output panel using the command Output: Show Output Channels => Python Locator
  • The first line will contain the executable path such as /home/vscode/.vscode-remote/extensions/ms-python.python-2024.15.2024092702-linux-x64/python-env-tools/bin/pet
  • Open a terminal and run the command <...see path path above>/python-env-tools/bin/pet find -v

Copy all of the output and paste it here.

@mhabibav
Copy link
Author

mhabibav commented Oct 1, 2024

@DonJayamanne No problem. Thanks for your time anyway, I really appreciate it :D

output of pet find -v
[2024-10-01T07:55:13Z TRACE pet_core::os_environment] Env PATH: ["/vscode/vscode-server/bin/linux-x64/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/bin/remote-cli", "/usr/local/share/nvm/versions/node/v20.17.0/bin", "/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", "/home/vscode/.local/bin", "/usr/local/py-utils/bin"]
[2024-10-01T07:55:13Z TRACE pet::find] Searching for environments in workspace folders: ["/workspaces/MY_WORKSPACE_FOLDER"]
[2024-10-01T07:55:13Z TRACE pet::find] Searching for environments in global venv folders: []
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: Conda
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: PyEnv
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: Poetry
[2024-10-01T07:55:13Z TRACE pet::find] Searching for environments in global folders: ["/vscode/vscode-server/bin/linux-x64/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/bin/remote-cli", "/usr/local/share/nvm/versions/node/v20.17.0/bin", "/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", "/usr/local/py-utils/bin", "/etc", "/lib", "/lib/x86_64-linux-gnu", "/lib64", "/usr/games", "/usr/include", "/usr/lib", "/usr/lib/x86_64-linux-gnu", "/usr/lib64", "/usr/libexec", "/usr/local", "/usr/local/etc", "/usr/local/games", "/usr/local/lib", "/usr/share", "/opt"]
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet_poetry] Poetry Manager Some(PoetryManager { executable: "/usr/local/py-utils/bin/poetry" })
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv versions directory not found
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: PyEnv in 468.829µs
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: PipEnv
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: PipEnv in 31.311µs
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: Poetry in 390.51µs
[2024-10-01T07:55:13Z TRACE pet_conda::environment_locations] Conda environments in known paths ["/bin", "/etc", "/lib", "/lib/x86_64-linux-gnu", "/lib64", "/opt", "/sbin", "/usr/bin", "/usr/games", "/usr/include", "/usr/lib", "/usr/lib/x86_64-linux-gnu", "/usr/lib64", "/usr/libexec", "/usr/local", "/usr/local/bin", "/usr/local/etc", "/usr/local/games", "/usr/local/lib", "/usr/local/py-utils/bin", "/usr/local/sbin", "/usr/local/share/nvm/versions/node/v20.17.0/bin", "/usr/sbin", "/usr/share", "/vscode/vscode-server/bin/linux-x64/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/bin/remote-cli"]
[2024-10-01T07:55:13Z TRACE pet_conda::environment_locations] No Conda environments in .condarc
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: VirtualEnvWrapper
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: VirtualEnvWrapper in 49.797µs
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: Venv
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: VirtualEnv
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: VirtualEnv in 138.091µs
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: Venv in 47.626µs
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: LinuxGlobal
[2024-10-01T07:55:13Z TRACE pet::find] Searching using locator: Homebrew
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: Homebrew in 148.537µs
[2024-10-01T07:55:13Z TRACE pet_python_utils::executable] Ignoring folder: "/workspaces/MY_WORKSPACE_FOLDER/.devcontainer"
[2024-10-01T07:55:13Z TRACE pet_python_utils::executable] Ignoring folder: "/workspaces/MY_WORKSPACE_FOLDER/.git"
[2024-10-01T07:55:13Z TRACE pet_python_utils::env] Executing Python: /usr/bin/python3 -c import json, sys; print('093385e9-59f7-4a16-a604-14bf206256fe');print(json.dumps({'version': '.'.join(str(n) for n in sys.version_info), 'sys_prefix': sys.prefix, 'executable': sys.executable, 'is64_bit': sys.maxsize > 2**32}))
[2024-10-01T07:55:13Z TRACE pet_python_utils::env] Executing Python: /bin/python3 -c import json, sys; print('093385e9-59f7-4a16-a604-14bf206256fe');print(json.dumps({'version': '.'.join(str(n) for n in sys.version_info), 'sys_prefix': sys.prefix, 'executable': sys.executable, 'is64_bit': sys.maxsize > 2**32}))
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet_conda::environment_locations] Time taken to get conda environment paths: 21.496302ms
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: Conda in 21.611188ms
[2024-10-01T07:55:13Z TRACE pet_python_utils::env] Executed Python "/bin/python3" in Ok(15.807049ms) & produced an output "093385e9-59f7-4a16-a604-14bf206256fe\n{\"version\": \"3.12.3.final.0\", \"sys_prefix\": \"/usr\", \"executable\": \"/bin/python3\", \"is64_bit\": true}"
[2024-10-01T07:55:13Z TRACE pet_python_utils::env] Executed Python "/usr/bin/python3" in Ok(16.398547ms) & produced an output "093385e9-59f7-4a16-a604-14bf206256fe\n{\"version\": \"3.12.3.final.0\", \"sys_prefix\": \"/usr\", \"executable\": \"/usr/bin/python3\", \"is64_bit\": true}"
[2024-10-01T07:55:13Z TRACE pet_python_utils::cache] Caching interpreter info for "/bin/python3"
[2024-10-01T07:55:13Z TRACE pet_python_utils::cache] Caching interpreter info for "/usr/bin/python3"
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet::find] Completed searching using locator: LinuxGlobal in 40.595361ms
[2024-10-01T07:55:13Z TRACE pet::locators] Env ("/usr/bin/python3") in Path resolved as Some(LinuxGlobal)
[2024-10-01T07:55:13Z TRACE pet::locators] Env ("/bin/python3") in Path resolved as Some(LinuxGlobal)
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet_python_utils::env] Executing Python: /bin/python3.12 -c import json, sys; print('093385e9-59f7-4a16-a604-14bf206256fe');print(json.dumps({'version': '.'.join(str(n) for n in sys.version_info), 'sys_prefix': sys.prefix, 'executable': sys.executable, 'is64_bit': sys.maxsize > 2**32}))
[2024-10-01T07:55:13Z TRACE pet_python_utils::env] Executing Python: /usr/bin/python3.12 -c import json, sys; print('093385e9-59f7-4a16-a604-14bf206256fe');print(json.dumps({'version': '.'.join(str(n) for n in sys.version_info), 'sys_prefix': sys.prefix, 'executable': sys.executable, 'is64_bit': sys.maxsize > 2**32}))
[2024-10-01T07:55:13Z TRACE pet_python_utils::env] Executed Python "/usr/bin/python3.12" in Ok(15.256951ms) & produced an output "093385e9-59f7-4a16-a604-14bf206256fe\n{\"version\": \"3.12.3.final.0\", \"sys_prefix\": \"/usr\", \"executable\": \"/usr/bin/python3.12\", \"is64_bit\": true}"
[2024-10-01T07:55:13Z TRACE pet_python_utils::cache] Caching interpreter info for "/usr/bin/python3.12"
[2024-10-01T07:55:13Z TRACE pet_python_utils::env] Executed Python "/bin/python3.12" in Ok(15.301092ms) & produced an output "093385e9-59f7-4a16-a604-14bf206256fe\n{\"version\": \"3.12.3.final.0\", \"sys_prefix\": \"/usr\", \"executable\": \"/bin/python3.12\", \"is64_bit\": true}"
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet_python_utils::cache] Caching interpreter info for "/bin/python3.12"
[2024-10-01T07:55:13Z TRACE pet_pyenv] PyEnv Info PyEnvInfo { exe: None, versions: None, version: None }
[2024-10-01T07:55:13Z TRACE pet::locators] Env ("/bin/python3.12") in Path resolved as Some(LinuxGlobal)
[2024-10-01T07:55:13Z TRACE pet::locators] Env ("/usr/bin/python3.12") in Path resolved as Some(LinuxGlobal)

Breakdown by each locator:
--------------------------
Conda                : 21.615731ms
Homebrew             : 167.6µs
LinuxGlobal          : 40.780144ms
PipEnv               : 72.335µs
Poetry               : 473.192µs
PyEnv                : 516.85µs
Venv                 : 388.981µs
VirtualEnv           : 192.29µs
VirtualEnvWrapper    : 57.012µs

Breakdown for finding Environments:
-----------------------------------
GlobalVirtualEnvs    : 952.331µs
Locators             : 43.185277ms
Path                 : 73.999175ms
Workspaces           : 5.82998ms

Managers:
---------
Poetry               : 1

Environments (2):
------------------
LinuxGlobal          : 2

Completed in 75ms

I can see here that the home directory is not searched at all.

@DonJayamanne
Copy link

@mhabibav
thanks for the update.

  • Out of curiosity how did you install poetry?
  • Also what do you get when you type poetry config --list into your terminal
  • Does your vscode workspace folder contain a pyproject.toml file (in the root directory of your workspace fodler)

@mhabibav
Copy link
Author

mhabibav commented Oct 1, 2024

@DonJayamanne

  • Through the devcontainer feature: "ghcr.io/devcontainers-contrib/features/poetry:2": {} . But I also tried running curl -sSL https://install.python-poetry.org | python3 - as a post create command and had the same issue.
  • Found below
  • No, I have multiple pyproject.toml files in multiple sub-folders and it was hell to switch between the Poetry environments with this bug present.
Output of poetry config --list
cache-dir = "/home/vscode/.cache/pypoetry"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
keyring.enabled = true
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/vscode/.cache/pypoetry/virtualenvs
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{project_name}-py{python_version}"
warnings.export = true

@DonJayamanne
Copy link

@mhabibav
Please can you install the latest pre-release version of the Python extension and share the logs of pet again
Hopefully it will work, if not will shed more info via the logs

@mhabibav
Copy link
Author

mhabibav commented Oct 1, 2024

I can't install the latest pre-release version.
image

@DonJayamanne
Copy link

DonJayamanne commented Oct 1, 2024

Please can you install the latest pre-release version of pylance as well
This should work.

@karthiknadig Any idea whats going on here?

@mhabibav
Copy link
Author

mhabibav commented Oct 2, 2024

I am on the latest compatible pre-release versions of Python, Pylance, Python Debugger extensions. The first time I hit install it installs the latest version, then shows this warning, and finally downgrades to v2024.15.2024091301 (pre-release).

Tried in a fresh container, got the same error.

@DonJayamanne
Copy link

Is it possible for you to install VS Code Insiders, and try again.
Unfortunately the pre-release version of Python extension requires the latest versions of VS Code, that would explain why it rolls back to 2024.15.*
Optionally the latest stable version of VS Code will be shipped some time tomorrow or the day after.

Once again thank you for your patience.

@mhabibav
Copy link
Author

mhabibav commented Oct 2, 2024

I'm not sure if I can install the insiders version, so I will be waiting for a couple days and try again then give you an update. Thanks a lot.

@mhabibav
Copy link
Author

mhabibav commented Oct 4, 2024

Hello @DonJayamanne I just updated VS Code and tried the pre-release version of the Python extension and it works perfectly!

Thanks a lot, you're a lifesaver ❤️

Please let me know when this will be included in the official release.

@karthiknadig
Copy link
Member

@mhabibav it should be included in the 2024.16.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants