2

I am trying to use pyproject.toml (and specifically setuptools_scm) in an isolated environment. My minimal pyproject.toml is:

[build-system]
requires = ["setuptools-scm"]

[tool.setuptools_scm]
write_to = "mypackage/version.py"

However, when trying to install my package in an isolated environment, I get:

$ pip3 install --no-index  -e .
Obtaining file:///home/…/myproject
  Installing build dependencies ... error
  error: subprocess-exited-with-error
  
  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [2 lines of output]
      ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none)
      ERROR: No matching distribution found for setuptools>=40.8.0
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

However, setuptools and setuptools_scm are already installed (setuptools 66.1.1, setuptools_scm 7.1.0). There is no legacy setup.py.

How can I ensure my package can be installed without network access (supposing that all dependencies are already resolved)?

olebole
  • 521
  • 4
  • 17

1 Answers1

1

How can I ensure my package can be installed without network access (supposing that all dependencies are already resolved)?

By having built a wheel out of it, and installing the wheel on the desert island machine.

If your package is PEP 517 compliant, use build:

(buildbox) $ pip install build
(buildbox) $ python -m build .
# whisk dist/*.whl to your isolated machine
(isolated) $ pip install ./*.whl

You can also use pip to download the rest of the dependency wheels (so long as you're using the same architecture, etc. as the target machine) – e.g. for something that uses scikit-learn:

$ pip download ./*.whl
Saved /scikit_learn-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /joblib-1.2.0-py3-none-any.whl
Saved /numpy-1.24.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /scipy-1.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Saved /threadpoolctl-3.1.0-py3-none-any.whl

Via the comments:

If you absolutely do need to build from source, either

  • ship the development dependencies as wheels and use --find-links so Pip can install them into the isolated build environment, or
  • set --no-build-isolation so Pip doesn't create a separate build environment, and uses the ambient build dependencies.
AKX
  • 152,115
  • 15
  • 115
  • 172
  • That does not work for me, as I need to install from source, in-place, in the isolated environment. – olebole Mar 03 '23 at 15:07
  • That sounds like a strange requirement. Why do you need to do that? – AKX Mar 03 '23 at 15:09
  • Customer requirement: Customer provides a machine with a defined environment, wants to install from source repository, and make sure nothing else is going to be installed. And installation must be possible without internet connection. – olebole Mar 03 '23 at 15:12
  • 1
    Fine; then you have two options: `pip install --no-build-isolation`, or ship `setuptools` and `setuptools_scm` _wheels_ to that machine and use `--find-links=...` in conjunction with `--no-index` so pip can install those in the isolated environment it would like to use to build the package. – AKX Mar 03 '23 at 15:15
  • `--no-build-isolation` is the solution here. Thanks. – olebole Mar 03 '23 at 15:18
  • No problem. Amended that into the answer, so you can accept it :) Have a great weekend! – AKX Mar 03 '23 at 15:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/252280/discussion-between-olebole-and-akx). – olebole Mar 03 '23 at 15:37