Streamlining Python Development: Making Copilot Use UV in Your Software Projects

Developer using Copilot and uv for Python development
Developer using Copilot and uv for Python development

Making GitHub Copilot Work with uv in Your Python Workflow

Many developers are constantly seeking ways to optimize their workflow and integrate new, efficient tools. A common question arises when using AI assistants like GitHub Copilot: how do you ensure it aligns with your preferred development environment and tools, especially for managing Python dependencies with a modern tool like uv?

A recent GitHub Community discussion highlighted this exact challenge. A developer attempted to configure Copilot to use uv for package management and virtual environments by adding a preference to user-preferences.md, but found it didn't take effect. This scenario is a great example of how understanding the nuances of AI tool integration can significantly impact developer productivity in software projects.

Understanding Copilot's Role: Assistance, Not Execution

The core insight from the discussion is crucial: GitHub Copilot assists you in writing code; it does not execute it. The execution of code, whether it's running a Python script or managing packages, is handled by your development environment – be it VS Code, your terminal, or another IDE. Therefore, telling Copilot you 'prefer uv' in a conversational context won't directly change how your system runs commands.

Instead of relying on Copilot to run commands, you should integrate uv directly into your workflow. For example, to run a Python script using uv, you'd use:

uv run main.py

This replaces the traditional python main.py. Over time, as you consistently use uv, Copilot may start to recognize and suggest these commands in comments or scripts, improving its contextual awareness for your software projects.

The Right Approach: Project-Level Configuration with .github/copilot-instructions.md

The user-preferences.md file is primarily for conversational context within Copilot Chat, helping it remember your preferences during a discussion. It doesn't dictate how Copilot interacts with your project's execution environment. For project-level behavior, especially when Copilot acts as an agent (e.g., Copilot Edits or chat with @workspace), the correct file to use is .github/copilot-instructions.md, located at the root of your project.

By adding instructions to this file, you can guide Copilot's behavior when it's actively generating or modifying code and interacting with your terminal. Here's an example of what you might include:

Always use `uv` for Python package management and virtual environments. When running Python scripts, use `uv run` instead of `python`. When creating virtual environments, use `uv venv` instead of `python -m venv`. When installing packages, use `uv pip install` instead of `pip install`.

This provides explicit directives that Copilot can follow when operating in agent mode, directly impacting how it suggests and executes commands within your software projects.

Deeper Integration for Enhanced Productivity

To further enhance the integration of uv with Copilot and your development environment, consider these additional steps:

  • Project Structure: Ensure you have a pyproject.toml or at least a .python-version file in your project root. uv uses these to automatically detect and manage virtual environments, and Copilot can pick up on this established structure.
  • VS Code Settings: For VS Code users, set "python.defaultInterpreterPath" in your .vscode/settings.json to point to your uv-managed virtual environment (e.g., ".venv/bin/python" or ".venv/Scripts/python" on Windows). This ensures that even non-agent Copilot suggestions are aware of your active virtual environment context, contributing to better overall workflow performance.

By implementing these strategies, you can effectively integrate uv into your Python development workflow, making Copilot a more intelligent and aligned assistant for your software projects, ultimately boosting your developer productivity.

Diagram showing Copilot instructions influencing project execution
Diagram showing Copilot instructions influencing project execution

Track, Analyze and Optimize Your Software DeveEx!

Effortlessly implement gamification, pre-generated performance reviews and retrospective, work quality analytics, alerts on top of your code repository activity

 Install GitHub App to Start
devActivity Screenshot