#๐Ÿ”’ .exe created using PyInstaller error

4 messages ยท Page 1 of 1 (latest)

lilac harness
#

I created a Python script and run it as a module. At some point I needed to use pkgutil to read in a file. To be honest I didn't comment in why so I can't remember why this was necessary but I remember having a hell of a time getting it to work.

I am fairly new to the concept of python modules and the like, so I know this might be a really obvious question.

data = pkgutil.get_data(__name__, "template.json")

that works great when running it in Python python -m MyModule

But I also want to provide an executable so users don't have to install Python and all the dependencies. I've been using pyinstaller to do that but now the executable throws an error at the pkgutil line.

  File "pkgutil.py", line 620, in get_data
  File "importlib\util.py", line 114, in find_spec
ValueError: __main__.__spec__ is None```

Is there some way to get this to work for both cases - running it from Python and as a packaged .exe?
viscid zephyrBOT
#

@lilac harness

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

viscid zephyrBOT
#

@lilac harness

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.