Help with Building pvporcupine Python Package on NixOS – FileExistsError

I am trying to build the pvporcupine Python package (version 3.0.5) using buildPythonPackage in NixOS, but I am encountering an issue during the build process. Specifically, the build fails with a FileExistsError, and the error log mentions that the file /build/pvporcupine-3.0.5/pvporcupine already exists.

Here is the relevant snippet of my Nix expression:

{ lib, buildPythonPackage, fetchPypi, setuptools, wheel, }:

buildPythonPackage rec {
  pname = "pvporcupine";
  version = "3.0.5";
  pyproject = true;

  src = fetchPypi {
    inherit pname version;
    hash = "sha256-SPkqsQqQS4Eeaa+xgXXSvUhXzOyL4JT0JEmWGoD6KvE=";
  };

  buildInputs = [ setuptools wheel ];

  pythonImportsCheck = [ "pvporcupine" ];

  meta = {
    description = "Porcupine wake word engine";
    homepage = "https://pypi.org/project/pvporcupine/";
    license = lib.licenses.unfree; # FIXME: nix-init did not find a license
    maintainers = with lib.maintainers; [ ];
  };
}

Error Log:

error: builder for '/nix/store/w96qbkynmh1k4ds7yqinpcdiw3bs5blb-python3.11-pvporcupine-3.0.5.drv' failed with exit code 1;
       last 25 log lines:
       > Creating a wheel...
       > * Getting build dependencies for wheel...
       > sh: git: not found
       > Traceback (most recent call last):
       >   File "/nix/store/hjx1hz74ic3ls6s613513zr5l885hj1l-python3.11-pyproject-hooks-1.0.0/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
       >     main()
       >   File "/nix/store/hjx1hz74ic3ls6s613513zr5l885hj1l-python3.11-pyproject-hooks-1.0.0/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 335, in main
       >     json_out['return_val'] = hook(**hook_input['kwargs'])
       >                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/hjx1hz74ic3ls6s613513zr5l885hj1l-python3.11-pyproject-hooks-1.0.0/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
       >     return hook(config_settings)
       >            ^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/g0lc2h0r8cc0w3k1qd7n5gr692qan4z9-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/build_meta.py", line 355, in get_requires_for_build_wheel
       >     return self._get_build_requires(config_settings, requirements=['wheel'])
       >            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/g0lc2h0r8cc0w3k1qd7n5gr692qan4z9-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in _get_build_requires
       >     self.run_setup()
       >   File "/nix/store/g0lc2h0r8cc0w3k1qd7n5gr692qan4z9-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/build_meta.py", line 507, in run_setup
       >     super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
       >   File "/nix/store/g0lc2h0r8cc0w3k1qd7n5gr692qan4z9-python3.11-setuptools-68.2.2/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in run_setup
       >     exec(code, locals())
       >   File "<string>", line 20, in <module>
       > FileExistsError: [Errno 17] File exists: '/build/pvporcupine-3.0.5/pvporcupine'
       >
       > ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel
1 Like

i get the same error.

pvporcupine = pkgs.python3Packages.buildPythonPackage rec {
        pname = "pvporcupine";
        version = "3.0.5";
        format = "pyproject";
        src = pkgs.fetchPypi {
          inherit pname version;  
          sha256 = "sha256-SPkqsQqQS4Eeaa+xgXXSvUhXzOyL4JT0JEmWGoD6KvE=";
        };
        doCheck = false;
        nativeBuildInputs = with pkgs.python3Packages; [ setuptools wheel pkgs.git];
        propagatedBuildInputs = with pkgs.python3Packages; [ setuptools];
        meta = with pkgs.lib; {
          description = "Porcupine - A lightweight wake word detection engine";
          license = licenses.mit;
        };
      };

error:

error: builder for '/nix/store/bw8qcskwp66h22qwzc59dvayj9fnm7n5-python3.12-pvporcupine-3.0.5.drv' failed with exit code 1;
       last 25 log lines:
       > pypa build flags: --no-isolation --outdir dist/ --wheel
       > * Getting build dependencies for wheel...
       > fatal: not a git repository (or any of the parent directories): .git
       > Traceback (most recent call last):
       >   File "/nix/store/h9y0b0g4h0gqd699pdyxss7xq8gg0kvh-python3.12-pyproject-hooks-1.2.0/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
       >     main()
       >   File "/nix/store/h9y0b0g4h0gqd699pdyxss7xq8gg0kvh-python3.12-pyproject-hooks-1.2.0/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
       >     json_out["return_val"] = hook(**hook_input["kwargs"])
       >                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/h9y0b0g4h0gqd699pdyxss7xq8gg0kvh-python3.12-pyproject-hooks-1.2.0/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel
       >     return hook(config_settings)
       >            ^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/chyqbfba0snalr78365hpd8imklspb4k-python3.12-setuptools-75.8.0/lib/python3.12/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel
       >     return self._get_build_requires(config_settings, requirements=[])
       >            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/chyqbfba0snalr78365hpd8imklspb4k-python3.12-setuptools-75.8.0/lib/python3.12/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
       >     self.run_setup()
       >   File "/nix/store/chyqbfba0snalr78365hpd8imklspb4k-python3.12-setuptools-75.8.0/lib/python3.12/site-packages/setuptools/build_meta.py", line 522, in run_setup
       >     super().run_setup(setup_script=setup_script)
       >   File "/nix/store/chyqbfba0snalr78365hpd8imklspb4k-python3.12-setuptools-75.8.0/lib/python3.12/site-packages/setuptools/build_meta.py", line 320, in run_setup
       >     exec(code, locals())
       >   File "<string>", line 20, in <module>
       > FileExistsError: [Errno 17] File exists: '/build/pvporcupine-3.0.5/pvporcupine'
       >
       > ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel
       For full logs, run 'nix-store -l /nix/store/bw8qcskwp66h22qwzc59dvayj9fnm7n5-python3.12-pvporcupine-3.0.5.drv'.
error: 1 dependencies of derivation '/nix/store/13swk0v2z3lc16fw26h7qk2xi33l9jrk-python3-3.12.9-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/1qrcyxnzs1dz9mjrc29h20hhvp6v423k-nix-shell-env.drv' failed to build

I found out that somehow the setup.py from the .tar.gz of pvporcupine-3.0.5 doesnt cope well with the way nix wants to build the package. I changed the setup.py where a new folder is created to:

if not os.path.exists(package_folder):
    os.mkdir(package_folder

but this leads to new errors like:

error: builder for '/nix/store/v751p3p6mbdljxyfma31c89gcm2yaqrs-python3.12-pvporcupine-3.0.5.drv' failed with exit code 1;
       last 25 log lines:
       >     main()
       >   File "/nix/store/h9y0b0g4h0gqd699pdyxss7xq8gg0kvh-python3.12-pyproject-hooks-1.2.0/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
       >     json_out["return_val"] = hook(**hook_input["kwargs"])
       >                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/h9y0b0g4h0gqd699pdyxss7xq8gg0kvh-python3.12-pyproject-hooks-1.2.0/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel
       >     return hook(config_settings)
       >            ^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/chyqbfba0snalr78365hpd8imklspb4k-python3.12-setuptools-75.8.0/lib/python3.12/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel
       >     return self._get_build_requires(config_settings, requirements=[])
       >            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/chyqbfba0snalr78365hpd8imklspb4k-python3.12-setuptools-75.8.0/lib/python3.12/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
       >     self.run_setup()
       >   File "/nix/store/chyqbfba0snalr78365hpd8imklspb4k-python3.12-setuptools-75.8.0/lib/python3.12/site-packages/setuptools/build_meta.py", line 522, in run_setup
       >     super().run_setup(setup_script=setup_script)
       >   File "/nix/store/chyqbfba0snalr78365hpd8imklspb4k-python3.12-setuptools-75.8.0/lib/python3.12/site-packages/setuptools/build_meta.py", line 320, in run_setup
       >     exec(code, locals())
       >   File "<string>", line 27, in <module>
       >   File "/nix/store/wz0j2zi02rvnjiz37nn28h3gfdq61svz-python3-3.12.9/lib/python3.12/shutil.py", line 435, in copy
       >     copyfile(src, dst, follow_symlinks=follow_symlinks)
       >   File "/nix/store/wz0j2zi02rvnjiz37nn28h3gfdq61svz-python3-3.12.9/lib/python3.12/shutil.py", line 260, in copyfile
       >     with open(src, 'rb') as fsrc:
       >          ^^^^^^^^^^^^^^^
       > FileNotFoundError: [Errno 2] No such file or directory: '/build/pvporcupine-3.0.5/__init__.py'
       >
       > ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel
       For full logs, run 'nix-store -l /nix/store/v751p3p6mbdljxyfma31c89gcm2yaqrs-python3.12-pvporcupine-3.0.5.drv'.
error: 1 dependencies of derivation '/nix/store/n0589z0abirb2cv9zpw3gkwjp5dqmx7f-python3-3.12.9-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/4w4nbgvld44b2k2adca2nn5bxvs58p5v-nix-shell-env.drv' failed to build

I looked into the setup.py file and found out that the setup.py file tries to copy multiple files around in the file system.

i downloaded the .tar.gz from pypi manually and changed the code snipped inside the flake.nix:

pvporcupine = pkgs.python3Packages.buildPythonPackage rec {
        pname = "pvporcupine";
        version = "3.0.5";
        format = "pyproject";
        src = ./pvporcupine-3.0.5.tar.gz;
        
        doCheck = false;
        nativeBuildInputs = with pkgs.python3Packages; [ setuptools wheel pkgs.git];
        propagatedBuildInputs = with pkgs.python3Packages; [ setuptools];
        meta = with pkgs.lib; {
          description = "Porcupine - A lightweight wake word detection engine";
        };
      };

aftwerwards i modified the setup.py like this:

import os
import setuptools

with open(os.path.join(os.path.dirname(__file__), 'README.md'), 'r') as f:
    long_description = f.read()

setuptools.setup(
    name="pvporcupine",
    version="3.0.5",
    author="Picovoice",
    author_email="hello@picovoice.ai",
    description="Porcupine wake word engine.",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/Picovoice/porcupine",
    packages=["pvporcupine"],
    include_package_data=True,  
    package_data={
        'pvporcupine': [
            'LICENSE',
            '__init__.py',
            '_porcupine.py',
            '_factory.py',
            '_util.py',
            'lib/*',  
            'resources/*',  
        ],
    },
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: Apache Software License",
        "Operating System :: OS Independent",
        "Programming Language :: Python :: 3",
        "Topic :: Multimedia :: Sound/Audio :: Speech"
    ],
    python_requires='>=3.9',
    keywords="wake word engine, hotword detection, keyword spotting, wake word detection, voice commands",
)

then run:

tar -czvf pvporcupine-3.0.5.tar.gz pvporcupine-3.0.5

and finally (I use flake.nix):

nix develop

now pvporcupine is installed in my flake environment. This is a very cumbersome solution. Do you know how to do it better and sustainable? I started look into nix yesterday and i havent much experience @tt619252615

Glad you got pvporcupine installed! Yeah, it does feel a bit cumbersome β€” I don’t have a better solution at the moment either