build icon indicating copy to clipboard operation
build copied to clipboard

ModuleNotFoundError: No module named 'dns'

Open jakbin opened this issue 7 months ago • 3 comments

While i run python -m build, i got this error

* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - setuptools >= 40.8.0
* Getting build dependencies for sdist...
Traceback (most recent call last):
  File "/home/codespace/.python/current/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "/home/codespace/.python/current/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 "/home/codespace/.python/current/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 317, in get_requires_for_build_sdist
    return hook(config_settings)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-9mbdx7qv/lib/python3.12/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_sdist
    return self._get_build_requires(config_settings, requirements=[])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-9mbdx7qv/lib/python3.12/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-9mbdx7qv/lib/python3.12/site-packages/setuptools/build_meta.py", line 512, in run_setup
    super().run_setup(setup_script=setup_script)
  File "/tmp/build-env-9mbdx7qv/lib/python3.12/site-packages/setuptools/build_meta.py", line 317, in run_setup
    exec(code, locals())
  File "<string>", line 2, in <module>
  File "/workspaces/whatweb/whatweb.py", line 5, in <module>
    import dns.resolver
ModuleNotFoundError: No module named 'dns'

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist

But i have installed dnspython.

Image

I got same error also on my local machine where i have installed python3-dnspython.

jakbin avatar May 11 '25 16:05 jakbin

It’s building in an isolated environment. You need to add this package to your build-system.requires in pyproject.toml.

henryiii avatar May 11 '25 20:05 henryiii

i am using setup.py.

jakbin avatar May 12 '25 02:05 jakbin

You need to have a pyproject.toml with at least this:

[build-system]
requires = ["setuptools", "dnspython"]
build-backend = "setuptools.build_meta"

That's what tells pip/build what to put in the environment it is building in. Or you can pass -n (--no-isolation for us, --no-build-isolation in pip) to disable isolation. Pip will currently not do an isolated build if pyproject.toml is missing, but I believe that is planned to change in about a year.

setup.py is just (one of, along with MANIFEST.in and setup.cfg) setuptools' configuration file.

henryiii avatar May 15 '25 05:05 henryiii

Closing since there's a way to resolve; please reopen if there's still any confusion!

henryiii avatar Aug 19 '25 15:08 henryiii