Skip to content
The Chat Archive
Geminigemini-2.5-pro· Google LMArena Human Preference 140K

Is there a way to configure uv to store all virtual environments in a central location…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with chatgpt-4o-latest-20250326’s answer.
  1. User

    Is there a way to configure uv to store all virtual environments in a central location instead of in the application folders?

  2. Assistant

    Of course! This is a very common workflow, and uv supports it by adopting the same convention used by the popular virtualenvwrapper tool.

    Yes, you can configure uv to store virtual environments in a central location by setting the WORKON_HOME environment variable.

    When this variable is set, uv will use that directory as the base for creating new named virtual environments.

    How to Configure Centralized Virtual Environments

    Here is a step-by-step guide to set it up.

    1. Choose and Create a Central Directory

    First, decide where you want to store all your virtual environments. A common choice is a hidden directory in your home folder, like ~/.virtualenvs.

    Create this directory if it doesn't exist:

    mkdir -p ~/.virtualenvs
    

    2. Set the WORKON_HOME Environment Variable

    You need to tell your shell where this central directory is. You do this by setting the WORKON_HOME environment variable.

    To set it for your current terminal session, you can run:

    export WORKON_HOME=~/.virtualenvs
    

    To make this setting permanent, you need to add this line to your shell's startup file.

    • For Bash: Add it to ~/.bashrc or ~/.bash_profile.

      echo 'export WORKON_HOME=~/.virtualenvs' >> ~/.bashrc
      source ~/.bashrc # To apply changes to the current session
      
    • For Zsh (common on macOS): Add it to ~/.zshrc.

      echo 'export WORKON_HOME=~/.virtualenvs' >> ~/.zshrc
      source ~/.zshrc # To apply changes to the current session
      
    • For Fish: Use the set command in ~/.config/fish/config.fish.

      # in ~/.config/fish/config.fish
      set -x WORKON_HOME ~/.virtualenvs
      

    3. How to Use It with uv

    Now that WORKON_HOME is set, the behavior of uv venv changes slightly.

    • Without a name: uv venv will still create a .venv in the current directory. This is the default, project-local behavior.

      cd my-app-folder
      uv venv # Creates ./my-app-folder/.venv
      
    • With a name: This is where WORKON_HOME is used. If you provide a name for your environment, uv will create it inside your central directory.

      cd my-app-folder
      
      # This will create the environment at ~/.virtualenvs/my-app
      uv venv my-app 
      
      # To check:
      ls ~/.virtualenvs
      # Output will include "my-app"
      

    Practical Workflow

    Here’s what a typical workflow looks like with this setup:

    1. Navigate to your project folder:

      cd ~/projects/my-cool-api
      
    2. Create a named virtual environment:

      # This creates the environment in $WORKON_HOME/my-cool-api-env
      uv venv my-cool-api-env
      
    3. Activate the environment: You still need to activate the environment using its full path. uv does not (yet) have a workon command like virtualenvwrapper.

      source $WORKON_HOME/my-cool-api-env/bin/activate
      
      # Your prompt will change, e.g., (my-cool-api-env) $
      
    4. Install packages: Now you can use uv to install packages into your activated, centralized environment.

      uv pip install fastapi "uvicorn[standard]"
      

    Comparison: Centralized vs. Project-Local

    Why use a central location? (WORKON_HOME)

    • Cleaner Project Directories: Your project folder isn't cluttered with a .venv directory. This is useful if you don't want it showing up in file searches or version control (even if it's in .gitignore).
    • Easy to Find/Manage All Envs: You can simply ls ~/.virtualenvs to see every virtual environment you've created on your system.
    • Name Reuse: Not generally recommended, but you could potentially use the same environment for multiple small, related projects.

    Why use the default project-local location? (.venv)

    • IDE/Tooling Integration: This is the biggest advantage. Tools like VS Code, PyCharm, and others are configured to automatically detect a .venv folder in your project's root. With a central location, you often have to manually configure your editor to find the Python interpreter for each project.
    • Self-Contained Projects: Everything the project needs is inside its folder. When you delete the project folder, you also delete its environment.
    • No Name Clashes: You never have to worry about two projects wanting the same environment name (e.g., api). Each one has its own .venv.

    Summary

    MethodCommandResultBest For
    Project-Local (Default)uv venvCreates ./.venvSimplicity, excellent IDE support, and self-contained projects.
    Centralized (Configured)uv venv <env-name>Creates $WORKON_HOME/<env-name>Keeping project folders clean and managing all envs in one place.
    Manual One-Offuv venv /path/to/envCreates an environment at a specific pathScripts or specific cases where you need full control over the location.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.