0

Windows 7 64-bit - Python 2.6 32-bit - Pymunk 4.0.0

Ok, Thanks to Using Pymunk with Pyinstaller . It took me a long time but I now understand how to throw anything I want into an exe with Pyinstaller. However, a particular dll-that is there-still fails to load-chipmunk.dll. Heres my .spec file for Pyinstaller.

# -*- mode: python -*-
a = Analysis(['Mesh_Animator.py'],
             pathex=['C:\\Users\\username\\workspace\\2D_Mesh_Animator'],
             hiddenimports=[],
             hookspath=None)
import os, pymunk
pymunk_dir = os.path.dirname(pymunk.__file__)
chipmunk_libs = [
    ('chipmunk.dll', os.path.join(pymunk_dir, 'chipmunk.dll'), 'BINARY'),
]
a.datas+=[('imagetest.jpg','imagetest.jpg','DATA')]
a.binaries+=chipmunk_libs
#or just
#a.binaries+=[('chipmunk.dll','chipmunk.dll','BINARY')]
#both seem to work the say way

pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'Mesh_Animator.exe'),
          debug=False,
          strip=None,
          upx=True,
          console=True )

This all packages no problem. The image loads fine as long as I have the dll next to the exe so I dont error. I confirmed the dll was in by comparing before and after versions of including the dll. 160 kb difference. Then I used this to check if the dll was in the current path when launched under Pyinstallers exe environment.

try:
    print os.listdir(sys._MEIPASS).count("chipmunk.dll"),"dlls"
except:
    #not in pyinstaller
    print 0,"dlls"

I get an exact 1 dlls on output but pymunk complains it couldn't find it. Its in the _MEIPASS PATH dir so how come pymunk can't find it? The dll is in the root so no searching should be required. How can I get pymunk to search the right location?

Community
  • 1
  • 1
Kaliber64
  • 586
  • 1
  • 5
  • 16

2 Answers2

0

I think it has to do with how pymunk tries to find the path of chipmunk.dll when frozen. Apparently special code is required when it all packs into one file. Can you replace your libload.py file with this one and try again: https://gist.github.com/viblo/44ccd6af88d9f050403b

(At the moment I cannot try this myself, therefor the gist. If it works Ill commit it to the real pymunk repo)

viblo
  • 4,159
  • 4
  • 20
  • 28
  • alright. I'll try that now. Sorry I'm so late. my Inbox client is failing to check my email lately. – Kaliber64 May 22 '14 at 00:52
  • File "C:\Users\kaliber\workspace\2D_Mesh_Animator\Mesh_Animator.py", line 892, in update self.Physical_World.step(elapsed) File "C:\Python26\lib\site-packages\pymunk\__init__.py", line 374, in step cp.cpSpaceStep(self._space, dt) ValueError: Procedure called with not enough arguments (12 bytes missing) or wrong calling convention – Kaliber64 May 22 '14 at 01:02
  • 1
    So. While running pyinstaller it loaded the dll while packaging. strange. BUT! It did load the dll whence the exe was ready. but I still get the above error. Sorry I have no idea how to fix the Procedure. – Kaliber64 May 22 '14 at 01:18
0

This piece of code seems to set a rather high priority on the path searched through when loading DLLs. You can put it at the very beginning of your entry point into your programme.

I had a similar issue and it works for me :)

try:
    import win32api
    win32api.SetDllDirectory(sys._MEIPASS)
except:
    pass 
xoolive
  • 341
  • 2
  • 15
  • Thanks a lot. I'll try that. The only biggy and I've dealt with it is- I just have to put the dll next to the final exe. Which isn't that big a deal. but I figured for some projects I'd like to be able to distribute just an exe. – Kaliber64 Sep 10 '15 at 02:10
  • That is how I dealt with mine: first identify the missing DLLs by putting them next to the exe. Then packing them with `a.binaries += (blah, blah, 'BINARY')` and adding the lines above there to set the directory where to search for DLLs. Then you can trash the DLLs next to the exe. Important thing to note: SetDllDirectory will prevent the exe to search for DLLs in the current directory, and look in `_MEIPASS` instead. Link to an interesting reference [here](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686203%28v=vs.85%29.aspx) – xoolive Sep 10 '15 at 08:21