Skip to content

Instantly share code, notes, and snippets.

@jbaranski
Created July 4, 2025 01:22
Show Gist options
  • Select an option

  • Save jbaranski/798f9100f0c6b32cababe1af99e0c365 to your computer and use it in GitHub Desktop.

Select an option

Save jbaranski/798f9100f0c6b32cababe1af99e0c365 to your computer and use it in GitHub Desktop.
uv CLI with embedded dependencies print out the virtual environment location
#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "typer"
# ]
# ///
import os
import sys
import typer
app = typer.Typer()
@app.command()
def env_info():
"""Show virtual environment information."""
print(f"Python executable: {sys.executable}")
print(f"Python prefix: {sys.prefix}")
venv = os.environ.get('VIRTUAL_ENV')
if venv:
print(f"VIRTUAL_ENV: {venv}")
else:
print("VIRTUAL_ENV not set")
# Check if we're in a virtual environment
if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
print(f"Virtual environment detected at: {sys.prefix}")
else:
print("Not in a virtual environment (or using system Python)")
if __name__ == "__main__":
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment