Skip to content

Use custom devcontainer images with unexpected python instalations #329

Open

Description

@DiamondRC

The uv setup relies on the standard devcontainer image which comes with the repo. If attempting to switch image, the default uv integration fails.

Resolved by clearing existing uv setup and installing fresh, then using $ uv venv --seed --system-site-packages to create the venv. Run programs with $ uv run python /workspaces/path_to_file/file.py.

Activity

  1. coretl commented on Mar 2, 2026

    @coretl
    Contributor

    So the only things I imagine you need to do are:

    • Ensure that uv is installed in the container in some way
    • Remove .python-version as you want to follow the version of python installed on the system, not pin it in the repo
    • Add uv venv --seed --system-site-packages && to the start of the postCreateCommand
    • Then the venv should be activated by default and you can just python /workspaces/path_to_file/file.py

    Does that work for you? If so this can be expanded into a how-to guide

  2. DiamondRC commented on Mar 2, 2026

    @DiamondRC
    Author

    Correct about removing .python-version, though I believe this is only required if you want to use a different python version, rather than just re-configuring uv.

    Using the suggested uv venv --seed --system-site-packages && prompts the user to explicitly clear existing .venv's upon container creation, adding the '--clear' flag makes this automatic.

    I'm now using "postCreateCommand": "cd /workspaces/deltabot_nn_controller && uv venv --seed --system-site-packages --clear && pip install pre-commit && pre-commit install --install-hooks"

    I believe you will then need to run the file as uv run python /workspaces/path_to_file/file.py instead of just python /workspaces/path_to_file/file.py if you'd like to use the new .venv.

    There's some other bits and pieces I needed to do for my exact use case (different image, use system packages, expose CUDA), so there's possibly some entanglement between that and a minimal setup.

  3. coretl commented on Mar 2, 2026

    @coretl
    Contributor

    I believe you will then need to run the file as uv run python /workspaces/path_to_file/file.py instead of just python /workspaces/path_to_file/file.py if you'd like to use the new .venv.

    But we already set the path here:

    "PATH": "/cache/venv-for${localWorkspaceFolder}/bin:${containerEnv:PATH}"
    so it should pick the correct environment up from that

  4. DiamondRC commented on Mar 2, 2026

    @DiamondRC
    Author

    I think you're right, I have "PATH": "${containerEnv:PATH}:/usr/local/cuda/bin", at the moment to detect the CUDA libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions