How to resolve FileNotFoundError UserDict.py when building a PIP project using Hatchling?

Viewed 9

I encountered the problem below when trying to build a pip package for a new release of my [SkillMetrics][1] package. I was following the instructions for [Packaging Python Projects][2] using the Hatchling build system instead of the standard setuptools.

% python3 -m build
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting dependencies for sdist...
* Building sdist...
* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting dependencies for wheel...
* Building wheel...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pep517/in_process/_in_process.py", line 351, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pep517/in_process/_in_process.py", line 333, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pep517/in_process/_in_process.py", line 249, in build_wheel
    return _build_backend().build_wheel(wheel_directory, config_settings,
  File "/private/var/folders/jy/p3021mrj5d54jd3wf686d0rc0000gp/T/build-env-tzuwjpjg/lib/python3.10/site-packages/hatchling/build.py", line 41, in build_wheel
    return os.path.basename(next(builder.build(wheel_directory, ['standard'])))
  File "/private/var/folders/jy/p3021mrj5d54jd3wf686d0rc0000gp/T/build-env-tzuwjpjg/lib/python3.10/site-packages/hatchling/builders/plugin/interface.py", line 144, in build
    artifact = version_api[version](directory, **build_data)
  File "/private/var/folders/jy/p3021mrj5d54jd3wf686d0rc0000gp/T/build-env-tzuwjpjg/lib/python3.10/site-packages/hatchling/builders/wheel.py", line 318, in build_standard
    record = archive.add_file(included_file)
  File "/private/var/folders/jy/p3021mrj5d54jd3wf686d0rc0000gp/T/build-env-tzuwjpjg/lib/python3.10/site-packages/hatchling/builders/wheel.py", line 59, in add_file
    file_stat = os.stat(included_file.path)
FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/jy/p3021mrj5d54jd3wf686d0rc0000gp/T/build-via-sdist-z4709rdv/skillmetrics-1.1.9/mitmenv/lib/python2.7/UserDict.py'

ERROR Backend subprocess exited when trying to invoke build_wheel
1 Answers

It turns out the problem occurs because of the presence of a mitmenv directory containing any old builds. To resolve the problem I simply removed the directory and all its contents. The build then ran flawlessly using python3:

% python3 -m build
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting dependencies for sdist...
* Building sdist...
* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting dependencies for wheel...
* Building wheel...
Successfully built skillmetrics-1.2.1.tar.gz and skillmetrics-1.2.1-py3-none-any.whl

I'm posting the problem with solution here to help others save their time in packaging a python project.

Related