2

I am trying to package some data alongside the scripts within a package of mine: https://pypi.org/project/taxon2wikipedia/0.0.4/

The source distribution seems to contain the files that I need, but when trying to use the package I get the error message:

FileNotFoundError: [Errno 2] No such file or directory: '~/my_venv/lib/python3.8/site-packages/taxon2wikipedia/dicts/phrase_start_dict.json'

The "data" and "dicts" folders are not there in "site-packages/taxon2wikipedia", but are present in the package when I manually download it? Any suggestions on why it might be happening?

Thanks!

Edit: extra information

I already have a MANIFEST.in file with recursive-include src *.rq *.py *.jinja *json, and even changing it to other similar options, it did not work. I am using a pyproject.toml configuration and a mock setup.py to run setuptools.setup(). I run python3 -m build to build the package. Maybe the problem lies there?

This is the source repository by the way: https://github.com/lubianat/taxon2wikipedia

The files in PyPI are all correct, but don't seem to be downloaded when I pip install the package.

Edit 2 - Related question

Why does "pip install" not include my package_data files?

It seems to be some problem with how pip installs the package. The solution is different as in my case the files seem to be at the correct directory.

Tiago Lubiana
  • 319
  • 1
  • 11

2 Answers2

1

You need a MANIFEST.in file in your source directory to tell the packaging process which non-Python files need to come along in a built package.

In your case, a MANIFEST.in file with

recursive-include taxon2wikipedia *.json

should do the trick.

Since .whl files are zips, you can use zipinfo dist/yournewwheel.whl to see that the files are there too before pushing a release.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • Thanks! I already have a MANIFEST.in file with `recursive-include src *.rq *.py *.jinja *json`, and even changing it to your option, it did not work. I am using a pyproject.toml configuration and a mock setup.py to run ` setuptools.setup()`. I run `python3 -m build` to build the package. Maybe the problem lies there? – Tiago Lubiana Jan 04 '23 at 16:24
  • 1
    The repo you've linked doesn't have a `MANIFEST.in`, and it's not using `pyproject.toml` for project metadata either. (Have you pushed your changes..?) `python -m build` is fine; it uses the backend you've specified in `pyproject.toml`. You don't need `setup.py` at all. – AKX Jan 04 '23 at 16:42
  • Indeed I had not pushed the changes (sorry about the mess) In the end was a bit of this issue: https://stackoverflow.com/questions/42791179/why-does-pip-install-not-include-my-package-data-files But mostly I should have included ``` [options.package_data] * = *.json *.jinja *.rq ``` In my setup.cfg . This seems to have done the trick. Thank you very much for the kind answers! – Tiago Lubiana Jan 04 '23 at 17:10
  • 2
    I would recommend moving fully to `pyproject.toml` instead of `pyproject.toml` and `setup.cfg`, e.g. with https://hatch.pypa.io/latest/ – AKX Jan 04 '23 at 17:12
1

I came across this blog post which helped me solve the issue: https://jwodder.github.io/kbits/posts/pypkg-data/ In the end, I was missing [options.package_data] * = *.json *.jinja *.rq from my setuf.cfg

Tiago Lubiana
  • 319
  • 1
  • 11