Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add uv venv --activate to activate virtual environment after creation #8106

Closed
imbev opened this issue Oct 10, 2024 · 6 comments

Comments

@imbev
Copy link

imbev commented Oct 10, 2024

I suggest that uv add an --activate option to the uv venv command. This option would automatically activate the virtual environment after creating it.

The following would be mostly equivalent:

uv venv
source .venv/bin/activate # Or shell equivalent
uv venv --activate

Currently, uv venv has the following output:

Using Python 3.12.6 interpreter at: /usr/bin/python3
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate

This should be replaced by the following, but only with --activate:

Using Python 3.12.6 interpreter at: /usr/bin/python3
Creating virtualenv at: .venv
Activating virtualenv at: .venv
@zanieb
Copy link
Member

zanieb commented Oct 10, 2024

Unfortunately we can't do this because of how shells work. You need to run the activation command from your shell, a subprocess cannot mutate your shell.

@Werni2A
Copy link

Werni2A commented Oct 10, 2024

Something related to this request that is probably not worth creating a separate issue.


Remembering the activation script location is confusing when switching between Windows and Linux systems. Windows makes it even worse with separate scripts for PowerShell and Command Prompt.

E.g.

  • foobar\Scripts\activate.ps1 (Windows PowerShell)
  • foobar\Scripts\activate (Windows Command Prompt)
  • foobar/bin/activate (Linux)

Sometimes it would be useful get the activation script path directly from uv to call or source it. E.g. with a imaginary argument --activation-script.

source $(uv venv foobar --activation-script)
# Leading to
# source "foobar/bin/activate"

Since uv already provides the exact command to activate the environment it's just copy and paste in an interactive environment. I.e. the benefit would be negligible but could make scripts a bit more consistent across shell implementations.

Nothing I personally require - just something that came to mind while reading this post.

@Ravencentric
Copy link

This is also what PDM went with, i.e., a command to print the activate command for your current OS and shell.

@Kilo59
Copy link

Kilo59 commented Oct 23, 2024

@zanieb
Both poetry and pipenv have a shell commands that works equivalent to this proposal.
Why can't uv do something similar?

@Ravencentric
Copy link

Poetry is removing their shell command in the next major update. python-poetry/poetry#9136

@zanieb
Copy link
Member

zanieb commented Oct 24, 2024

See #1910

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

No branches or pull requests

6 participants