Installing NumPy in a Flatpak

I have a Flatpak in which I have successfully installed Python, but using the same method to install NumPy or CV2 fails. What am I doing wrong?

    {
      "name": "numpy",
      "buildsystem": "simple",
      "build-commands": [
        "pip3 install . --prefix=${FLATPAK_DEST}"
      ],
      "sources": [
        {
          "type": "archive",
          "url": "https://github.com/numpy/numpy/releases/download/v2.2.2/numpy-2.2.2.tar.gz",
          "sha256": "ed6906f61834d687738d25988ae117683705636936cc605be0bb208b23df4d8f"
        }
      ]
    },

Installing build dependencies … error
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> [7 lines of output]
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f02d5461090>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)': /simple/meson-python/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f02d5461e90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/meson-python/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f02d54629d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/meson-python/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f02d5463510>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/meson-python/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f02d5463f50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)': /simple/meson-python/
ERROR: Could not find a version that satisfies the requirement meson-python>=0.15.0 (from versions: none)
ERROR: No matching distribution found for meson-python>=0.15.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.
Error: module numpy: Child process exited with code 1
FB: Unmounting read-only fs: fusermount -uz /home/chris/.flatpak-builder/rofiles/rofiles-h2YWry
Finished

There is a mention of Meson - but I’m not explicitly using Meson.

Meson is the build backend for numpy. So it’s trying to build numpy from source, rather than using a wheel.

I’m not sure if this is because it just can’t resolve anything (hence the network errors) or something else.

1 Like

“Meson is the build backend for numpy” I haven’t got Meson installed, so I imagine the failure is because the process can’t find it. I’ve taken your hint that using a wheel is the better method.

      "name": "numpy",
      "buildsystem": "simple",
      "build-commands": [
        "pip3 install --no-index --find-links=/app/files numpy"
      ],
      "sources": [
        {
          "type": "file",
          "url": "https://files.pythonhosted.org/packages/7c/28/8754b9aee4f97199f9a047f73bb644b5a2014994a6d7b061ba67134a42de/numpy-2.2.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
          "sha256": "e0d4142eb40ca6f94539e4db929410f2a46052a0fe7a2c1c59f6179c39938d2a",
          "dest": "files/"
        }
      ]
    },

Defaulting to user installation because normal site-packages is not writeable
Looking in links: /app/files
WARNING: Location ‘/app/files’ is ignored: it is either a non-existing path or lacks a specific scheme.
ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy
Error: module numpy: Child process exited with code 1
FB: Unmounting read-only fs: fusermount -uz /home/chris/.flatpak-builder/rofiles/rofiles-h2YWry
Finished

Using a wheel isn’t in-and-of itself the solution, but the fact that pip couldn’t find one is a clue that there’s something funky in the environment. Packages like numpy tend to have platform-specific wheels and perhaps the flatpak is making things confusing.

What python version are you using? What OS/distribution?

1 Like

Fedora-41. Python 3.13.1, is what’s available in the OS, in the Flatpak org.gnome.Platform-45 it’s 3.12.
I’ve found something here, bodged it a bit and it can now be built, although I haven’t tested whether the package works yet. There might be problems relating to different architectures too, but it’s a start.

{
  "name": "python-numpy",
  "buildsystem": "simple",
  "build-commands": [
    "pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} --no-build-isolation *.whl"],
  "sources": [
    {
      "type": "file",
      "only-arches": [
        "x86_64"
      ],
      "url": "https://files.pythonhosted.org/packages/3a/d0/edc009c27b406c4f9cbc79274d6e46d634d139075492ad055e3d68445925/numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
      "sha256": "666dbfb6ec68962c033a450943ded891bed2d54e6755e35e5835d63f4f6931d5"
    }
  ]
},

{
  "name": "opencv-python",
  "buildsystem": "simple",
  "build-commands": [
    "pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} --no-build-isolation *.whl"],
  "sources": [
    {
      "type": "file",
      "only-arches": [
        "x86_64"
      ],
      "url": "https://github.com/cudawarped/opencv-python-cuda-wheels/releases/download/4.11.0.86/opencv_contrib_python-4.11.0.86-cp37-abi3-linux_x86_64.whl",
      "sha256": "f6571929815c3e64ebe02e41485defcd339a4624c423fc70854caf875e290877"
    }
  ]
},

Note that the code for open-cv shouldn’t have been included in my previous post.

I’ve now built the package successfully. Here is ChatGPT’s explanation of the parameters:

1. --no-index
What it does: Prevents pip from trying to fetch packages from PyPI or other configured package indexes.
Why it’s necessary: In a Flatpak build environment, network access might be disabled or restricted. Without --no-index, pip may still attempt to connect to PyPI even though you’re using a pre-downloaded wheel. This flag ensures that only the provided wheel file is used.

2. --find-links="file://${PWD}"
What it does: Tells pip to look for packages in the current directory (or another specified directory).
Why it’s necessary: pip needs to know where to find the wheel file, and this flag explicitly directs it to the directory containing the .whl file. ${PWD} (present working directory) ensures it references the build directory during the Flatpak build process.

3. --no-build-isolation
What it does: Disables the use of an isolated build environment when installing the package.
Why it’s necessary: Some Python wheels include metadata or dependencies that might otherwise trigger an unnecessary build process. By disabling build isolation, pip uses the current environment without attempting to rebuild anything.

4. --exists-action=i
What it does: Specifies what action to take if the destination already contains the installed files. The i option (ignore) tells pip to ignore and not overwrite existing files.
Why it’s helpful: Prevents overwriting or reinstalling already-installed packages, which can be useful during iterative builds.