-
Notifications
You must be signed in to change notification settings - Fork 21
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
Detect venv set to $VIRTUAL_ENV
#180
Comments
This is different from when you activate a venv and it automatically sets this variable to itself. Am talking about a user setting this variable in their dotfiles. One could put this "global" venv on the |
I wouldn't say it's "common", but is a hack some people have used to work around code which checks that variable as a way to determine if a virtual environment is set. But as the docs point out, that environment variable is only meant to signify when a virtual environment is activated and not as a way to tell other apps, "use this system install". We also wouldn't want to promote working around externally-managed Python installs as the OS vendors set that specifically because they don't want users installing into them and some tools assume virtual environments can bn installed into. |
Where did system installs or OS pythons come from? I am specifically talking about a venv here. From the docs:
As you can see, activating a venv isn't mandated. You surely are not saying that a large amount of use cases (data science, etc) don't require the presence of a global venv (pyenv, etc install their venvs to a central location for a reason), are you? For tools that don't have a central location for venvs like |
Also, just fyi, setting an externally-managed installation to this env var won't make it not externally managed xD Even if it did, pet has got nothing to do with that use case because it is supposed to locate installations (which it already does for externally managed installs anyway) and not install packages into it. pet is not pip. |
Just like pet tries to locate venvs in various places like the workspace itself, many central locations used by tools, user paths like
It says "use this env var to locate venvs except when it is not set for some reason". Currently, pet doesn't even check this env var to begin with. If anything, pet is going against the docs here. |
Sorry, misread '"global" venv' as '"global" env'.
I'm aware as I am the one who opened the issue on CPython to make that abundantly clear in the docs.
What does "global" mean to you in this instance? A virtual environment that is shared across multiple projects or a virtual environment that's meant to be used for a single project, but having it stored outside of the project directory?
As someone who wrote a bunch of those PEPs, I'm acutely aware of what uv does and does not implement based on specs, convention, and what they just chose to do simply because they thought it was a good idea.
It could. I'm just pushing back on your assertion that people manually setting |
Let me explain my case. In fields like data science, a global environment with a certain set of packages are always needed for quick prototyping, running notebooks, etc. (imagine a bunch of tightly nit packages like numpy, scikit-learn you get the idea). This used to be the system python install before externally managed installs came along. Then tools like pyenv were used to create a venv with this environment and put it on the
So a virtual environment that is used as a fallback for when a project specific venv is not present. Like how the system install used to be used when a venv was not activated back in the days.
This is the first solution that comes to mind, why not put it on Plus, we get one more problem with this approach: venvs created using the python on So what we need is a way to locate/use this global venv without putting it on |
Also, I am exposed to pet via vscode and zed, which are editors. So whenever I open a data science script to have a quick look, I should not be expected to create a venv (each time, for a script) and then install those same packages repeatedly that I know I already have in a venv but the editor (actually pet) is not able to locate that even if I activate it. If you have any other way, I'll be happy to hear. |
Inline script metadata should eventually take care of that for you by creating and caching a virtual environment on the fly. |
Setting a path to a venv to
$VIRTUAL_ENV
is a common way to signify a "global" venv, which should be used if a project-level venv is not present. This is especially true after system level python installs have become externally managed PEP668 on almost all platforms (debian, ubuntu, brew, etc.)The text was updated successfully, but these errors were encountered: