【问题标题】:Using Pymunk with Pyinstaller将 Pymunk 与 Pyinstaller 一起使用
【发布时间】:2013-02-01 05:37:39
【问题描述】:

我确实没有发现任何可以提供帮助的谷歌搜索。即使对于 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

Chipmunk 库是通过 ctypes 模块包装的,因此只要这些消息来自 Chipmunk,它就假定它正在被编译。从 Python 的角度来看,这对我没有帮助。也许不会。

谁能告诉我如何修复 pyinstaller 的这种依赖关系?

【问题讨论】:

    标签: python pyinstaller chipmunk pymunk


    【解决方案1】:

    您需要包含 chipmunk.dll 文件(如果您想在 osx 上运行它,则需要 .dylib 文件,而对于 linux,则需要 .so 文件)。一个快速的 hacky 选项是手动将其复制到生成的 .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(请注意,这个例子在开始时有一点路径黑客,它在 sys.path.insert(0,'..') 的位置。假设你的程序已经可以找到 pymunk 并且你把将规范文件放在同一个地方,您将不需要该部分。

    【讨论】:

    • 哈哈。如果我找到了我正在寻找的 dll,我就不会发布这个问题。得出的结论是没有。我刚刚在查看 StackExchance 更新之前找到了它 XD。我把它放在exe旁边,一切都很好。感谢这个例子,我一定会试一试的。
    【解决方案2】:

    我在使用带有 pymunk==6.0.0 的 pyinstaller 时遇到了同样的问题

    解决方法是将pymunk文件夹中的_chipmunk.pyd文件重命名为chipmunk.dll。

    根据此答案,它们是相同的文件类型,但具有不同的扩展名,此解决方法使编译器能够找到文件并完成其任务。 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.

    【讨论】:

    • 我试图从使用 Arcade 模块制作的程序中编译一个 exe。重命名对我不起作用,因为具有原始名称的文件需要它。我所做的是复制_chipmunk.pyd,然后将其重命名为chipmunk.dll。如果没有这个答案,我不会想出它,谢谢 c:
    猜你喜欢
    • 2018-07-22
    • 2019-08-06
    • 2016-12-21
    • 2021-05-17
    • 2018-05-23
    • 1970-01-01
    • 2020-02-21
    • 2020-12-20
    • 2018-05-04
    相关资源
    最近更新 更多