Skip to content

Conversation

@nooscraft
Copy link
Contributor

When users try to run 'uv activate', show a helpful error message
instead of the generic unknown command error. The message explains
that 'uv activate' is not supported and provides instructions on
how to activate a virtual environment.

This is most probably address the issue: #16993

When users try to run 'uv activate', show a helpful error message
instead of the generic unknown command error. The message explains
that 'uv activate' is not supported and provides instructions on
how to activate a virtual environment.

This addresses issue astral-sh#16993.
@nooscraft
Copy link
Contributor Author

@charliermarsh @zanieb FYI!

@nooscraft
Copy link
Contributor Author

   error `uv activate` is not supported. To activate a virtual environment, use:
     source .venv/bin/activate

   hint Create a virtual environment with: uv venv

Copy link

@darth-raijin darth-raijin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion about some possibly redundant comments

);
}
"activate" => {
// Handle "activate" with a helpful error message

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The code already makes this intent pretty clear, so these two comments might be redundant. Fine to keep, but you could consider removing.

@zanieb
Copy link
Member

zanieb commented Dec 5, 2025

I'm still not sure we should do this, but if we do, we probably need to actually use our shell detection logic as well as discover the virtual environment to ensure one exists?

@darth-raijin
Copy link

+1 on the above.

It feels like it could set a precedent for adding similar custom messages for other unsupported commands, instead of handling them in a more general way.

- Detect user's current shell (Bash, Zsh, Fish, Nushell, Csh, PowerShell, Cmd)
- Search for virtual environment in current and parent directories
- Provide shell-specific activation command with correct path
- Show helpful hint when no venv is found

Addresses feedback from @zanieb to use shell detection logic
and discover the virtual environment.
@nooscraft
Copy link
Contributor Author

nooscraft commented Dec 7, 2025

Hey, updated this based on @zanieb's feedback!

Now it actually detects your shell and finds the venv instead of just printing static text. Walks up from cwd looking for .venv/pyvenv.cfg, checks ZSH_VERSION/FISH_VERSION/etc to figure out what shell you're in, and gives you the right command.

Quick examples:

$ uv activate
error `uv activate` is not supported. To activate a virtual environment, use:
  source .venv/bin/activate

If you're in fish:

$ uv activate
error `uv activate` is not supported. To activate a virtual environment, use:
  source .venv/bin/activate.fish

No venv? Shows a hint:

$ uv activate
error `uv activate` is not supported. To activate a virtual environment, use:
  source .venv/bin/activate

hint Create a virtual environment with: uv venv

@darth-raijin - fair point on precedent, but we already do this for install, show, freeze etc (they suggest uv pip <cmd>). This one's a bit different since there's no actual command to suggest - just need to explain why uv activate can't be a thing and point them to the shell command.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants