How can pip be used locally with custom metapath finder?

I have a somewhat unusual environment in that I need to archive every package I install, and I need to install them in nonstandard places in the directory tree.

I have a custom metapath finder that’s loaded by, which is able to find the packages I’ve installed.

Up until now, I’ve done package installation with, but as that’s not supported anymore, I’m trying to move it to pip.

My recipe for installing packages is:

unpack tarball
python3 -m pip install --prefix=/some/nonstandard/place --no-deps --ignore-installed --no-index .

This is manual and tedious, but given that I need to archive everything that’s installed, I’m downloading each package and installing them in dependency order.

My metapath finder implements find_spec() (so import can find modules in non-standard places) and find_distributions() (so package metadata can also be found in non-standard places). Module import works fine, and so does “pip list”. I see everything that I’ve installed.

My problem is that when I use “pip install” (the previous recipe) for a package that has a dependency, pip install complains that it cannot be found, even though the dependent module with the correct version is already installed.

  ERROR: Could not find a version that satisfies the requirement flit-core>=3.4 (from versions: none)
  ERROR: No matching distribution found for flit-core>=3.4

Scanning through pip’s source code, it looks like the “versions: none” comes from a search of the index, but since I’m not using an index, there’s nothing to find. I don’t know why it’s looking in the index at all, though, given that the module in question is already installed and shows up in “pip list”. Is there something I’m missing?

Maybe you need to disable “build isolation”.

That worked! If I understand correctly, in the isolated environment my probably wasn’t being called so my packages weren’t being found. Is that it?

Yup, exactly. Specifically, what wasn’t being found was your build-time dependencies (flit, your build backend, as declared in your build-system.requires), rather than your runtime deps (in project.dependencies).