在Pyinstaller中使用Pymunk [英] Using Pymunk with Pyinstaller

查看:139
本文介绍了在Pyinstaller中使用Pymunk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从字面上看,我没有发现任何可以帮助您的信息。即使对于py2exe,我也想使用pyinstaller。

I have literally found nothing googling that could help. Even for py2exe but I would like to use pyinstaller.

我的问题是exe版本中未完全包含模块(pymunk [aka Chipmunk])。它可能缺少某种dll。基本上,它缺少我不知道如何解决的依赖性。

My problem is the module (pymunk[aka Chipmunk]) is not fully included in the exe build. It is probably missing some kind of dll. Basically its missing a dependency I don't know how to solve.

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的角度来看,这无济于事。

The Chipmunk Library was wrapped via the ctypes module so as far as these messages go from Chipmunk it's assuming it's being compiled. Which doesn't help me in a Python standpoint. Maybe not.

有人可以告诉我如何为pyinstaller修复此依赖性吗?

Can anyone tell me how to fix this dependency for pyinstaller?

推荐答案

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

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.

类似的东西:

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干线。看看 https://github.com/viblo/pymunk/ blob / master / examples / pyinstaller_basic_test.spec (请注意,此示例在开始执行sys.path.insert(0,'..')的过程中就存在一点路径黑客。鉴于您的程序已经可以找到pymunk,然后将规范文件放在不需要该部分的位置。

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.

这篇关于在Pyinstaller中使用Pymunk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆