Accessing data files from within an egg

I have a package with a default json file in case the user hasnt supplied one data = pkgutil.get_data(__name__, "deprecated.json")

when running stand-alone this works fine

But if I run python install to create my.egg The run easy_install my.egg Finally start the executable I get an error message [Errno 2 nosuch file or director: `d:\\work\\pythonvenv\\lib\\site-packages\\my.egg\\PackageName\\depercate.json

    return loader.get_data(resource_name)
  File "<frozen importlib._bootstrap_external>", line 972, in get_data

I thought the purpose of using pkgutil.get_data was to prevent this type of issue?


  • Modify your file to include package_data as in

        package_data={'pkgName': ["path/to/deprecated.json"]},

    Another way to achieve the same behavior is to create a file with the contents include path/to/deprecated.json and then in your setup function include the argument include_package_data=True. This is detailed in