-
Notifications
You must be signed in to change notification settings - Fork 410
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
Virtual environments break on Homebrew upgrades due to using a Cellar
link
#1640
Comments
Do you by any chance have a link to the relevant PRs or issues in |
I don't, but FWIW |
Hmm yeah, we're using ❯ python3.8
Python 3.8.18 (default, Aug 24 2023, 19:48:18)
[Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys._base_executable
'/opt/homebrew/bin/python3.8' |
The problem is that we're calling |
We may want something like...
That's closer to virtualenv: # if we're not in a virtual environment, this is already a system python, so return the original executable
# note we must choose the original and not the pure executable as shim scripts might throw us off
return self.original_executable |
I don't know if it's quite relevant but they just fixed a bug by storing the resolved absolute path in the metadata file that is generated for virtual environments: pypa/virtualenv#2682 Also, I know all of you are basically Rust experts, but in case I am reading the source correctly please never ever use canonicalize directly as it is literally (I'm not joking) broken on Windows and will cause all of us bugs and unexpected behavior. Please don't use it. Instead, it's common to use the dunce crate or the normpath crate when you don't want to resolve symlinks. See even Armin talking about it. |
Haha. We do use |
I'd actually expect that virtualenv change to break this case, if I'm reading it correctly:
So now |
I don't own a macOS to test that for you unfortunately but that sounds right. |
On |
\cc @gaborbernat -- it seems like |
I do not have a good answer here. 😱 |
Agreed, i think this is better, i'm also thinking about the use case where somebody might have intentional redirects for their python setup. For the Cellar issue, note that technically different patch versions aren't compatible from a packaging perspective, technically a project could require |
On Homebrew, virtual environments created by
uv venv
reference the Python installation underCellar
in their interpreter symlink andpyvenv.cfg
, which has the full downstream version in its path. These virtual environments break when Homebrew upgrades the respective Python package to the next maintenance release. In recent versions ofvenv
andvirtualenv
, this issue was resolved by using the stable link under$(brew --prefix)/opt/python@3.x/
instead. For example, on Python 3.11 macOS aarch64 this would be the interpreter in/opt/homebrew/opt/python@3.11/bin
.This shell session demonstrates the problem:
When Homebrew upgrades its
python@3.11
package and cleans up the old installation underCellar
, those references in the virtual environment start to dangle.For comparison, here's what I get with
venv
from Homebrew'spython@3.11
installation:And with
virtualenv
:❯ virtualenv --version virtualenv 20.25.0 from ~/.local/pipx/venvs/virtualenv/lib/python3.12/site-packages/virtualenv/__init__.py ❯ virtualenv .venv ❯ readlink .venv/bin/python /opt/homebrew/opt/python@3.12/bin/python3.12 ❯ grep ^home .venv/pyvenv.cfg home = /opt/homebrew/opt/python@3.12/bin
Affected platforms: Linux and macOS with Homebrew Python
The text was updated successfully, but these errors were encountered: