Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python3 -m build gives ModuleNotFoundError: No module named 'pathlib2'

I am trying to build a Python package, but it gives the following error.

* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting dependencies for sdist...
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/pep517/in_process/_in_process.py", line 351, in <module>
    main()
  File "/usr/local/lib/python3.10/site-packages/pep517/in_process/_in_process.py", line 333, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/usr/local/lib/python3.10/site-packages/pep517/in_process/_in_process.py", line 285, in get_requires_for_build_sdist
    return hook(config_settings)
  File "/tmp/build-env-eyqolcf7/lib/python3.10/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_sdist
    return self._get_build_requires(config_settings, requirements=[])
  File "/tmp/build-env-eyqolcf7/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-eyqolcf7/lib/python3.10/site-packages/setuptools/build_meta.py", line 482, in run_setup
    super(_BuildMetaLegacyBackend,
  File "/tmp/build-env-eyqolcf7/lib/python3.10/site-packages/setuptools/build_meta.py", line 335, in run_setup
    exec(code, locals())
  File "<string>", line 5, in <module>
ModuleNotFoundError: No module named 'pathlib2'

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist

I have already installed pathlib2. What is the solution?

like image 255
Eftal Gezer Avatar asked Feb 06 '26 14:02

Eftal Gezer


2 Answers

In python 3.9, installing build module solved the problem (it was not there initially).

python -m pip install build
like image 95
John Prawyn Avatar answered Feb 08 '26 03:02

John Prawyn


As per the official documentation of the build package, it does not have a stable compatibility

https://pypa-build.readthedocs.io/en/latest/installation.html#compatibility

You can try switching to an older version of python (3.9 recommended) and try again, ideally, that should solve the error since in traceback, the error seems to originate from setuptools ( which will be automatically reverted back to an older version with a older python version )

NOTE: You will also need to reinstall build in the new python version

Let me know if you face any issues with it.

like image 45
Divyessh Avatar answered Feb 08 '26 05:02

Divyessh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!