1

I have a python package which has several data files in a data folder which have to be read when the package is used; these are not python scripts. However when I install my package to test it with python setup.py install --user only an ~/.local/lib/python2.7/site-package/mypackage-1.0.0-py2.7.egg is installed and so the code can't read the data directory.

I see other packages like numpy install with a *.dist-info and a numpy folder.

How do I make my package install like that?

Aage Torleif
  • 1,907
  • 1
  • 20
  • 37
  • Isn't the whole idea of subfolders that they are not installed directly but need to be imported like `import mypackage.data.whatever`? Here is a question about this http://stackoverflow.com/questions/8953844/import-module-from-subfolder or you can refer to the [`module documentation`](https://docs.python.org/3/tutorial/modules.html#packages) – ImportanceOfBeingErnest Nov 19 '16 at 17:42
  • That has nothing to do with 'How do I make my package install like that?' And what is the point of `MANIFEST.in` or a `include_package_data` in `setuptools.setup` if I'm meant to just use the method you described? – Aage Torleif Nov 19 '16 at 17:52
  • As I understand it, `include_package_data` is meant to be used for non-python files like readme, docs, raw data, images etc. This is at least what I get from the [python-packaging docs](https://python-packaging.readthedocs.io/en/latest/non-code-files.html). – ImportanceOfBeingErnest Nov 19 '16 at 17:58
  • Exactly. When did I say I wanted to execute a script? I'll update my question for clarity. – Aage Torleif Nov 19 '16 at 18:03
  • Ok, that was a missing piece of information, maybe it was my mistake. Anyways, so did you try to use a `MANIFEST.in`, specify your data files in it, like `include data/*.*` and finally `include_package_data=True` in setuptools? What do you actually mean by "and so the code can't read the data directory."? Why shouldn't it read the data directory? Doesn't that depend on the code and not on the installation? – ImportanceOfBeingErnest Nov 19 '16 at 18:27
  • "did you try to ...specify your data files" Yes. "What do you actually mean" Literally what I said, that file/folder doesn't exist in an egg, so it cannot read it. "Why shouldn't it read the data directory" Because an egg is a file and not a directory. Rather, the data + files do exist in the .egg format, but they have to be read with pkg_resources module which isn't suitable. This is about how to install a package with a source directory and a `*.dist-info` inside `*site-packages`, nothing else. – Aage Torleif Nov 19 '16 at 18:36
  • So, did you use `zip_safe = False` and still get only the egg-file and no extracted version of it in the site-packages folder? If you really want to get dist-info then you need to use wheels instead of eggs. – ImportanceOfBeingErnest Nov 19 '16 at 18:58

1 Answers1

3
python setup.py sdist
pip install dist/*.tar.gz --user

sdist creates a Source Archine as a tar.gz inside dist/. pip then installs it to the users site-packages directory.

More info here.

Aage Torleif
  • 1,907
  • 1
  • 20
  • 37