使用Pymunk和Pyins

2024-04-20 00:34:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我在谷歌上没有发现任何有用的东西。即使对于py2exe,但是我想使用pyinstaller。在

我的问题是模块(pymunk[aka Chipmunk])没有完全包含在exe构建中。它可能缺少某种dll。基本上它缺少一个我不知道如何解决的依赖关系。在

Failed to load pymunk library.

This error usually means that you don't have a compiled version of chipmunk in
the correct spot where pymunk can find it. pymunk does not include precompiled
chipmunk library files for all platforms.

The good news is that it is usually enough (at least on *nix and OS X) to
simply run the compile command first before installing and then retry again:

You compile chipmunk with
> python setup.py build_chipmunk
and then continue as usual with
> python setup.py install
> cd examples
> python basic_test.py

(for complete instructions please see the readme file)

If it still doesnt work, please report as a bug on the issue tracker at
http://code.google.com/p/pymunk/issues
Remember to include information about your OS, which version of python you use
and the version of pymunk you tried to run. A description of what you did to
trigger the error is also good. Please include the exception traceback if any
(usually found below this message).

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "C:\python26\lib\site-packages\PyInstaller\loader\iu.py", line 386, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "C:\python26\lib\site-packages\PyInstaller\loader\iu.py", line 480, in doimport
    exec co in mod.__dict__
  File ".\build\pyi.win32\CollisionUtil\out00-PYZ.pyz\pymunk", line 53, in <module>
  File "C:\python26\lib\site-packages\PyInstaller\loader\iu.py", line 431, in importHook
    mod = self.doimport(nm, ctx, ctx + '.' + nm)
  File "C:\python26\lib\site-packages\PyInstaller\loader\iu.py", line 480, in doimport
    exec co in mod.__dict__
  File ".\build\pyi.win32\CollisionUtil\out00-PYZ.pyz\pymunk._chipmunk", line 14, in <module>
  File ".\build\pyi.win32\CollisionUtil\out00-PYZ.pyz\pymunk.libload", line 68, in load_library
  File ".\build\pyi.win32\CollisionUtil\out00-PYZ.pyz\ctypes", line 431, in LoadLibrary
  File ".\build\pyi.win32\CollisionUtil\out00-PYZ.pyz\ctypes", line 353, in __init__
WindowsError: [Error 126] The specified module could not be found

花栗鼠库是通过ctypes模块包装的,所以这些消息来自花栗鼠它假设它正在被编译。从Python的角度来看,这对我没有帮助。也许不是。在

有人能告诉我如何修复pyinstaller的依赖关系吗?在


Tags: thetoinpybuildlinepyzfile
1条回答
网友
1楼 · 发布于 2024-04-20 00:34:02

你需要包括花栗鼠.dll文件(如果你想在osx上运行.dylib文件,在linux上运行.so文件)。一个快捷的方法是手动将其复制到生成的.exe文件所在的位置。另一个选择是让pyinstaller为您包含它。我不是pyinstaller的专家,但是一种方法是编辑pyinstaller创建的.spec文件。在

比如:

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'))

我创建了一个完整的示例并将其提交给pymunk trunk。看一下https://github.com/viblo/pymunk/blob/master/examples/pyinstaller_basic_test.spec(注意,这个例子在开始的地方有一点路径黑客系统路径插入(0,“…)。如果你的程序已经可以找到pymunk,并且你把spec文件放在同一个地方,你就不需要这个部分了。在

相关问题 更多 >