-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[python3] Do not ensurepip. Provide venv instructions. #24906
[python3] Do not ensurepip. Provide venv instructions. #24906
Conversation
+@ResearchDaniel to chime in since they're actively using embedded python via vcpkg :) |
So, if I understand everything correctly one would:
|
I don't fully know how things would work in the install case. Maybe you can simply take the modules out of the "build" virtual environment and ship them with your application? I assume there's some C api for the python interpreter that you would call to point it at that folder to find modules. |
Would not the “build” virtual environment contain the non-relocatable pip in that case? I want to clarify that I think the PR sounds reasonable. I am mainly thinking about how to deal with it in an application. I have made an example setup using CMake, vcpkg and Python that I would like to adjust to properly include pip. My example works on Mac/Windows/Linux, but I do not test adding new packages via pip after the application has been installed so it might not catch the case described in this PR. |
I assume that the user doesn't want pip as part of their final install :) If you're developing an application, I assume you want to use pip at build time to install whatever python modules you want to be available at runtime/install time -- then "extract" those out to include them in your installer. If you actually want your installed product to have a functioning pip, then I do suppose the final application would want to use a venv as well; but that's several leaps outside my experience. edit: Just to make sure we're on the same page with vocabulary:
|
perhaps I missed something, but why is pip not being re-locatable a problem in that case? This solution would only move the problem to the virtual environment? Our use case is probably not the most common one, but we develop a visual analysis tool which comes with pre-existing algorithms and users can also write new ones (optionally using Python). In some cases they might want to bring in new modules to load/process data which means that including pip in the installed app is a nice to have feature. |
An essential feature of vcpkg is binary caching, which assume packages can be moved to different paths on the machine. Any binary that hardcodes paths into its build folder or install prefix is incompatible with that model (without performing "fixups" at install time, which vcpkg strongly wishes to avoid).
In a certain sense yes; because pip is unrelocatable, we're explaining to the user how to perform the fixups for their environment (i.e. the I don't know your application's distribution model, but it would be very strange to have a mechanism that writes back to The bonus of having this be in a user data location is because it enables each user to extend the product without being a system administrator. There might be some much more clever PYTHON_PATH manipulation that I don't know about to chain your Program Files location and avoid copying it into the user's private environment. |
stupid question but isn't the pip executable/binary the only thing which has the embedded path? |
The virtual environment will in some cases point to the vcpkg_install/tools/python3 directory (if symlinks are used), so I think that moving it would break the virtual environment unless it is possible to force it to copy the binaries. https://docs.python.org/3/library/venv.html |
Yes, sounds like a good solution. We do something in line with that for other user-created content.
We will in that case add both the bundled and the user-local Python module directories to the Python sys path so I don’t think copying is necessary, but have not tested yet. We are aiming to use isolated mode, so it should not intervene with other Python environments. |
I should mention that the initial version of #22386 did exactly what this PR does (without the instruction): pip installation was postponed and this is the only adequate thing we can do about pip |
Ok, sounds like this is an improvement over the current situation. Thanks everyone! |
[python3] Do not ensurepip. Provide venv instructions. (microsoft#24906)
This PR removes
pip
entirely from ourpython3
package, because it is by design not relocatable1. Instead, we add usage instructions for users that wantpip
about how to build a full virtual environment, enabling them to get a pip and install packages without modifying the vcpkg installed folder.Additional Unix usage:
Additional Windows usage:
This PR is an alternative followup from #22386.
+@mkhon +@Hoikas +@dg0yt for comments on this approach