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?

4

2 回答 2

0

我认为这与 pymunk 在冻结时如何尝试找到 chipmunk.dll 的路径有关。当全部打包到一个文件中时,显然需要特殊代码。你能用这个替换你的 libload.py 文件,然后再试一次:https ://gist.github.com/viblo/44ccd6af88d9f050403b

(目前我不能自己尝试这个,因此要点。如果它有效,我会把它提交给真正的 pymunk repo)

于 2014-05-14T16:23:02.117 回答
0

这段代码似乎对加载 DLL 时搜索的路径设置了相当高的优先级。您可以将它放在程序入口点的最开始。

我有一个类似的问题,它对我有用:)

try:
    import win32api
    win32api.SetDllDirectory(sys._MEIPASS)
except:
    pass 
于 2015-09-09T09:48:40.140 回答