/pipx-in-pipx

Bootstrap your pipx with pipx.

Primary LanguagePythonApache License 2.0Apache-2.0

pipx-in-pipx

Latest Version Supported Python Versions Code style: black
docs read-the-docs Documentation Status
tests static analysis Static Analysis
tests all tests Tests

pipx is great for keeping your CLI tools isolated and your system Python paths clean. However, it still requires that you install pipx itself in your system Python.

But pipx is a CLI tool installed through pip...why not install pipx with pipx? Why not indeed!

With pipx-in-pipx, all you need to do is install :

$ pip install pipx-in-pipx

But wait! You say. Didn't you just say that we shouldn't install things to system Python?

Yes. What pipx-in-pipx actually does is slightly (but only slightly) evil. Rather than actually installing anything when you run "install", pipx-in-pipx instead builds a temporary virtual environment, installs pipx there, and then uses that pipx to install pipx in your user local space, just like any other pipx-installed tool.

What you end up with is a pipx installation that is itself managed by pipx.

Sharp Edges

Which Python?

By default, pipx uses its own Python for each environment that it creates. This is whatever you used when you installed pipx. This is most commonly the system Python, but if you use pipx-in-pipx to install your pipx, it is the Python binary in the pipx-managed virtualenv for pipx. This, in turn, points to the Python that you used to install pipx-in-pipx.

This has a few notable side effects:

  1. If you uninstall your pipx-managed pipx (pipx uninstall pipx), all of the tools that you installed using that pipx will stop working because their Pythons suddenly point to nothing.
    • If you do this, you can fix it by installing pipx-in-pipx again.
  2. If you reinstall all pipx packages (pipx reinstall-all), this uninstalls your pipx-managed pipx.
    • If you do this, you can fix it by installing pipx-in-pipx again.
    • If you want to reinstall all other packages, tell pipx to ignore pipx (pipx reinstall-all --skip pipx).
    • To reinstall pipx, install pipx-in-pipx again.
  3. Because all pipx-managed packages use the Python in the pipx virtualenv, you can change the Python for all packages by installing pipx-in-pipx again.

Uninstalling

pipx has a handy feature to uninstall all pipx-managed tools. Because you have now made pipx manage itself, running pipx uninstall-all will also uninstall pipx.

This is not a bug, but a feature. By installing pipx using pipx-in-pipx, you have expressed an intent that you want pipx to manage itself. If that's not what you want, this is not the tool for you.

If you at any point uninstall your pipx-managed pipx, you can simply pip install pipx-in-pipx again to rebuild it.