question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ship pip as a standalone application

See original GitHub issue

Actually, it occurred to me that we may even be able to do this right now. I put together a very simple proof of concept and it seems to work. If you put the following script alongside a “lib” directory with pip installed into it (pip install pip --target lib) but with the bin and pip*.dist-info directory removed (so the bundled pip isn’t visible in pip list) then it can be run from any Python interpreter to effectively act as a copy of pip in that environment.

#!/usr/bin/env python

import runpy
import sys
import os

lib = os.path.join(os.path.dirname(__file__), "lib")
sys.path.insert(0, lib)

runpy.run_module("pip", run_name="__main__")

I don’t think it would take much to turn this into a viable “standalone pip” application (I’d mostly just want to set up an executable wrapper for Windows). I’ve done some very basic testing - this would need a lot more real-world testing to make sure there aren’t any problem edge cases, but it basically seems to work.

_Originally posted by @pfmoore in https://github.com/pypa/pip/issues/11223#issuecomment-1179518843_

For now, this is just a placeholder to discuss whether we want to do this at all, or how we’d distribute it. The main point here is that with a script like this, there would no longer be a need to install pip in every virtual environment.

One thing we’d have to work out is what tools assume that pip is available in every environment. I’m thinking of environment managers and IDEs, like nox, or VS Code. The ecosystem implications here are likely to be more complicated than the technical issues. Maybe we need to start with a heads-up discussion on Discourse? But before we do that I’d like to make sure the pip committers are all on board with the idea…

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:41 (41 by maintainers)

github_iconTop GitHub Comments

2reactions
pfmoorecommented, Jul 10, 2022

For what it’s worth, I’ve just created https://github.com/pfmoore/runpip

The build script is there, and I’ve published a 22.1.2 release that has the pyz as a downloadable asset. If people want to play with it, go ahead. I think I’m going to make it my default pip locally and see how that works out.

1reaction
sbidoulcommented, Jul 26, 2022

While we are brainstorming, something comes to my mind… would it make any sense for ensurepip (or python -m venv?) to install pip by placing a .pth in the target environment (pointing to the wheel, a zip, or an unpacked copy of pip) ? That would

  • solve the venv initialization performance problem
  • use a central copy of pip
  • keep python -m pip
  • but that would not install the pip scripts
Read more comments on GitHub >

github_iconTop Results From Across the Web

Standalone app deployment story - Packaging
A central place to put packages on, like PyPI, and an “official” way to install, like pip. Maintainers don't want to host releases,...
Read more >
Create, build and ship a Python3 pip module in 5 minutes
PyShipper is an automation part, doing the grunt-work of setting up a module structure, adds some boilerplate code, and provides a pipeline ...
Read more >
Distributing Standalone Python Applications
But if you are distributing Python applications - standalone executables that use Python - your world can be much more complicated.
Read more >
Packaging Your Python App Into Standalone Executables
Easily Package your python app into executables which you can distribute to anyone, without the need of them installing Python or other ...
Read more >
Packaging and Shipping Python Apps for the Desktop
What this means is, if you have an app that's to be used commercially and you don't want to share its source code,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found