Is it possible for python to write to its own zip archive?
For example, I'd like to be able to install a pip upgrade and other packages inside the ape archive:
$ ./python -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in /zip/Lib/site-packages (23.1.2)
Collecting pip
Downloading pip-24.1-py3-none-any.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 23.6 MB/s eta 0:00:00
Installing collected packages: pip
WARNING: The scripts pip, pip3 and pip3.11 are installed in '/Users/roy/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-24.1
But it looks like the path /zip/Lib is not writable from within python execution, so it defaults to $HOME/.local/bin instead.
Is there a way to enable writing to /zip/Lib/site-packages?
/zip is read only. See this.
/zip used to be writable on Linux/FreeBSD (definitely back when it was zip:) but it had too many edge cases and weird interactions, so the feature was removed. For adding packages (like say click) to Python APEs, I usually run:
./python.com -m pip download click
mkdir -p ./Lib/site-packages
cd Lib/site-packages
unzip ../../click*.whl
cd ../../
zip -qr python.com Lib/
I wonder if it's possible to patch pip or setuptools to do the above thing automatically for a pip install.