Created
July 4, 2025 01:22
-
-
Save jbaranski/798f9100f0c6b32cababe1af99e0c365 to your computer and use it in GitHub Desktop.
uv CLI with embedded dependencies print out the virtual environment location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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