0

I have this folder structure:

my-package -
            |- src/mypackage
            |- resources/some-resources
            |- setup.py
            |- setup.cfg

I want to load some-resources from within mypackage. How do I do this? I have read online I should update my setup.py to include:

setup(
    ...
    package_data={"": ["resources"]},
    include_package_data=True,
    ...
)

And that I should then be able to use pkg_resources to access my resource folder. But the examples seem like they are incomplete, e.g. pkg_resources.resource_listdir("mypackage", "") (one suggestion) just lists the python files in mypackage. So to reiterate - how do I include resources in my package, and then access them from my code?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Conor
  • 535
  • 2
  • 8
  • 16
  • Maybe you need `listdir("mypackage", "resources")`? By the way I could not find `pkg_resources.listdir` in the `pkg_resources` module. – Kota Mori Oct 12 '22 at 13:15
  • sorry - yes, that should be: `resource_listdir`. No luck, it just seems to list the contents of the package, which is just the python code.. so I don't know where the "resource" folder should be accessed/if it's even been added with those setup changes – Conor Oct 12 '22 at 13:19
  • https://stackoverflow.com/a/54953494 -- https://stackoverflow.com/a/58941536 – sinoroc Oct 12 '22 at 14:37

0 Answers0