I have the same situation like here, here, here, and here. I followed the advice given in those questions and I still get the FileNotFoundError.
--tree--
.
MANIFEST.in
setup.py
...
--src
|--__init__.py
|--mypkg
|--__init__.py
|--module_1.py # dosth_1() in module_1 needs somedata.json
...
|--data
|--__init__.py
|--somedata.json
|--someotherdata.txt
...
--setup.py--
packages=["mypkg"],
package_dir={"": "src"},
package_data={"mypkg": ["data/*.txt", "data/*.json"]},
--after removing the old build--
(venv)$ python3 -m build
...
copying src/mypkg/somedata.json -> .../src/mypkg/data
...
adding 'mypkg/data/somedata.json'
...
--next--
- upload the mypkg to PyPI
- pip install mypkg (within a different vEnv)
--open python interpreter--
>>from mypkg import module_1
>>res = module_1.dosth_1()
--throws error--
... File "/usr/lib/python3.8/importlib/resources.py", line 82, in _check_location raise FileNotFoundError(f'Package has no location {package!r}') FileNotFoundError: Package has no location <module 'mypkg.data' (namespace)>
So I'm really confused why this happens. I took care of the init.py, I did the setup.py as advertised, and if I understand the build comments correctly the data file is added to the build. Still the installed package has no access to the data. What's wrong here?