I'm trying to build a python script which then I add to a zip file using python -m zipapp
.
Everything works fine until it tries to read in my json config file, because it can't find it using directory string like "config.json" (config.json is at the root of the folder where all my code is in). So I found something that looks like it will help, which is importlib.resources.open_text("Package Name", "config.json")
. The problem is that since all my python code is at the root of the folder I've created, I don't know what "Package Name" should be. Is there a default package name? And also, do I need to create __init__.py
for this to work? My program works fine without __init__.py
when I just run it from command-line like python __main__.py #(my entry point is in __main__.py)
Edit: I tried using "__package__"
but that variable is empty.