[Tutor] Issues with converting python file to .exe

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Nov 25 09:16:46 EST 2019


On Mon, 25 Nov 2019 at 13:54, Mikael Lenander
<mikael.lenander1 at gmail.com> wrote:
>
> I tried to make an .exe file with python so that I could run my program
> without python and I could send it to my friends. I installed pyinstaller
> and gave this command through the command prompt successfully: "pyinstaller
> --onefile pää.py". The application is saved in the same folder as all the
> dependencies (for example images). However, when I try to open my program,
> this error occurs:
>
> "pygame 1.9.6
> Hello from the pygame community. https://www.pygame.org/contribute.html
> Traceback (most recent call last):
>   File "pää.py", line 91, in <module>
>     fontti = pygame.font.Font('freesansbold.ttf', 22)
>   File "site-packages\pygame\pkgdata.py", line 50, in getResource
>   File "site-packages\pkg_resources\__init__.py", line 1134, in
> resource_exists
>   File "site-packages\pkg_resources\__init__.py", line 1404, in has_resource
>   File "site-packages\pkg_resources\__init__.py", line 1472, in _has
> NotImplementedError: Can't perform this operation for unregistered loader
> type
> [2636] Failed to execute script põõ".

The problem is that pygame is attempting to load a font file. I guess
that font file would normally be located somewhere among the pygame
source code so pygame attempts to load it using pkg_resources which
should be able to handle extracting it from e.g. a zip file. However
given that the resource is embedded within the exe it seems that
pkg_resources doesn't understand somehow how to extract the file from
the exe.

It looks like someone has some advice on this here:
https://stackoverflow.com/a/36456473/9450991

I think that the one file approach for Python applications is
generally problematic though so I would recommend investigating
alternatives. Given that Python is now easily installed from the
Windows app store you might want to see what it would take to make
your program runnable for someone who already has Python installed.
For example you could bundle pygame and your app code in a zip file
and that might work better:
https://docs.python.org/3/library/zipapp.html#creating-standalone-applications-with-zipapp

--
Oscar


More information about the Tutor mailing list