Skip to content Skip to sidebar Skip to footer

Using Pymunk With Pyinstaller

I have literally found nothing googling that could help. Even for py2exe but I would like to use pyinstaller. My problem is the module (pymunk[aka Chipmunk]) is not fully included

Solution 1:

You need to include the chipmunk.dll file (and if you want to run it on osx the .dylib file, and for linux the .so files). One quick hacky option is to just manually copy it to where your generated .exe file is located. The other option is to get pyinstaller to include it for you. I am no expert of pyinstaller, but one way to do it is to edit the .spec file that pyinstaller creates.

Something like:

import os, pymunk
pymunk_dir = os.path.dirname(pymunk.__file__)
chipmunk_libs = [
    ('chipmunk.dll', os.path.join(pymunk_dir, 'chipmunk.dll'), 'DATA'),
]
#... 
coll = COLLECT(exe,
               a.binaries + chipmunk_libs,
               a.zipfiles,
               a.datas,
               strip=None,
               upx=True,
               name=os.path.join('dist', 'basic_test'))

I created a full example and committed it to pymunk trunk. Take a look at https://github.com/viblo/pymunk/blob/master/examples/pyinstaller_basic_test.spec (Note that this example have a little bit of path hackery in the start where it does sys.path.insert(0,'..'). Given that your program already can find pymunk and you put the spec file in the same place you will not need that part.


Solution 2:

I ran into the same problem using pyinstaller with pymunk==6.0.0

The solution was to rename the _chipmunk.pyd file in the pymunk folder to chipmunk.dll.

According to this answer, they are the same file type, but with a different extension, this workaround enabled the compiler to locate the file and finish its task. https://stackoverflow.com/questions/8262884/python-c-extension-use-extension-pyd-or-dll#:~:text=4%20Answers&text=pyd%20files%20are%20just%20dll,from%20normal%20dlls%2C%20I%20recommend%20.&text=dll%20in%20windows.


Post a Comment for "Using Pymunk With Pyinstaller"