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

Unable to activate VIRTUAL_ENV when CONDA_PREFIX exists #2028

Closed
YuShigurey opened this issue Feb 28, 2024 · 5 comments · Fixed by #2574
Closed

Unable to activate VIRTUAL_ENV when CONDA_PREFIX exists #2028

YuShigurey opened this issue Feb 28, 2024 · 5 comments · Fixed by #2574
Assignees
Labels
question Asking for clarification or support virtualenv Related to virtual environments

Comments

@YuShigurey
Copy link

YuShigurey commented Feb 28, 2024

I'm trying out uv, together with hatch-pip-compile (and hatch). venv creation works fine, and speed is significantly faster, great!

Except when I try to run command with created virtual env, error raises

(base)  test-hatch-pip-compile$ hatch run default1:python
error: Both VIRTUAL_ENV and CONDA_PREFIX are set. Please unset one of them.

The error message is clean, that's great, and I can fix it on my computer in 5 seconds (conda deactivate).
I just wonder if there is any difficulty makes this "user action" necessary?

Here is the hatch.toml (very likely unrelated imo since hatch is just an invoker and after I deactivated conda environment everything looks ok)

[env]
requires = [
    "hatch-pip-compile",
]

[envs.default]
path = ".venv/default"

[envs.default1]
path = ".venv/default1"
type = "pip-compile"
pip-compile-installer = "uv"
pip-compile-resolver = "uv"

Thank you!

@zanieb zanieb added question Asking for clarification or support virtualenv Related to virtual environments labels Feb 28, 2024
@charliermarsh
Copy link
Member

@konstin - Thoughts?

@konstin
Copy link
Member

konstin commented Feb 28, 2024

We could have VIRTUAL_ENV take precedence over CONDA_PREFIX if the python in PATH is from that venv; I'm not sure what behavior conda users would expect.

@ananis25
Copy link

ananis25 commented Mar 18, 2024

We could have VIRTUAL_ENV take precedence over CONDA_PREFIX if the python in PATH is from that venv; I'm not sure what behavior conda users would expect.

This'd be useful, same error came up when using Rye to set up a new project, while the global python comes from Conda.
Having a base conda/mamba env activated is useful for one-off scripts (Rye is a bit new to use everywhere).

@matthewfeickert
Copy link

This also happens if you try to have uv be installed globally with pixi via pixi global install uv.

The easy alternative is just to globally install uv itself, but it is nice to have pixi global be able to manage all your tools with a pixi global upgrade-all.

@notatallshaw
Copy link
Contributor

We could have VIRTUAL_ENV take precedence over CONDA_PREFIX if the python in PATH is from that venv; I'm not sure what behavior conda users would expect.

When conda is activated it can be considered a globally available Python, therefore when a virtual environment is activated in a conda environment it is equivalent to a virtual environment being activated when there is a system install, the virtual environment should take precedence.

This has come up a few of times on pip issues, I'll try and find the discussion .

But anecdotally when I was a heavy conda user this is what I would have expected.

konstin added a commit that referenced this issue Mar 20, 2024
It is a common pattern to have an active conda base env (that sets `CONDA_PREFIX`) and then create a venv on top of that (setting `VIRTUAL_ENV`).

Previously, we would error when both `VIRTUAL_ENV` and `CONDA_PREFIX` were set, now `VIRTUAL_ENV` takes precedence over `CONDA_PREFIX`.

Fixes #2028
charliermarsh pushed a commit that referenced this issue Mar 20, 2024
It is a common pattern to have an active conda base env (that sets
`CONDA_PREFIX`) and then create a venv on top of that (setting
`VIRTUAL_ENV`).

Previously, we would error when both `VIRTUAL_ENV` and `CONDA_PREFIX`
were set, now `VIRTUAL_ENV` takes precedence over `CONDA_PREFIX`.

Fixes #2028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support virtualenv Related to virtual environments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants