简体   繁体   English

py2app built app在其他机器上显示`ERROR:pygame.macosx import FAILED`

[英]py2app built app displays `ERROR: pygame.macosx import FAILED` on other machines

Trying to build an app on the Mac using py2app. 尝试使用py2app在Mac上构建应用程序。 Got everything working fine on my machine, but when moving the app to another, it crashes and the console displays this error. 在我的机器上一切正常,但是当将应用程序移动到另一台时,它会崩溃并且控制台会显示此错误。

ERROR: pygame.macosx import FAILED

Anybody have a solution to this? 有人有解决方案吗?

Found the problem and solution after many hours. 几个小时后发现问题和解决方案。 Turns out other people have experienced similar problems and their articles were quite helpful: 结果发现其他人遇到了类似的问题,他们的文章非常有帮助:

http://b.atcg.us/blog/2010/04/13/py2app-hell-the-first.html http://b.atcg.us/blog/2010/04/13/py2app-hell-the-first.html

http://www.vijayp.ca/blog/?p=62 http://www.vijayp.ca/blog/?p=62

In case someone else runs into the issue, this particular problem was caused because the Python framework was not being bundled into the application. 如果其他人遇到此问题,则会导致此特定问题,因为Python框架未捆绑到应用程序中。 You can confirm this by right-clicking your app to view package contents, then proceed to Contents/Frameworks/. 您可以通过右键单击您的应用程序以查看包内容来确认,然后进入目录/框架/。 If Python.framework is not there, it should be. 如果不存在Python.framework,那应该是。

Be sure to download Python - My first issue was reliance on Apple's build in Python package. 一定要下载Python - 我的第一个问题是依赖Apple的Python包构建。 Don't use this. 不要使用它。 You need to install your own version of python. 您需要安装自己的python版本。 Go to http://www.python.org/download/releases/ , find a version (I stuck with 2.6), download the gzip (not the mac package), and install with the following if you are running Snow Leopard: 转到http://www.python.org/download/releases/ ,找到一个版本(我坚持使用2.6),下载gzip(不是mac包),如果你正在运行Snow Leopard,请安装以下内容:

./configure --enable-framework MACOSX_DEPLOYMENT_TARGET=10.6 --with-universal-archs=intel --enable-universalsdk=/
make
sudo make install

Adjust Paths, Install Packages - From here there you need to adjust your paths to ensure you are using your custom-installed version. 调整路径,安装包 - 从这里您需要调整路径以确保您使用自定义安装的版本。 From here, I reinstalled the following packages - this turned out to be a dependency nightmare so I'm including the version numbers as well: 从这里,我重新安装了以下软件包 - 这被证明是一个依赖性的噩梦,所以我也包括版本号:

  • py2app 0.5.2 py2app 0.5.2
  • macholib 1.3 macholib 1.3
  • modulegraph .8.0 modulegraph .8.0

If these packages actually worked, you should be able to build and run your app now. 如果这些软件包确实有效,您应该能够立即构建和运行您的应用程序。 Unfortunately, they don't. 不幸的是,他们没有。 I'll go into the errors and my hacked solutions in a bit, but there's some settings in the build file that need to be made first. 我会稍微介绍一下错误和我的黑客攻击解决方案,但是构建文件中有一些需要先设置的设置。

First the setup.py file should like a little somethin' like this: 首先,setup.py文件应该像这样:

setup.py setup.py

from setuptools import setup

APP = ['Game.py']
DATA_FILES = ['data']

OPTIONS = {
    "argv_emulation": False,
    "compressed" : True,
    "optimize":2, 
    "iconfile":'data/game.icns',        
}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
)

then to be extra safe, I use a shell script to call this. 然后为了更加安全,我使用shell脚本来调用它。

build.sh build.sh

## Remove previous builds.  Start with clean slate.
rm -rf build dist

## Force python into 32 bit mode.
export VERSIONER_PYTHON_PREFER_32_BIT=yes

## Force build with custom installed python
/Library/Frameworks/Python.framework/Versions/2.6/bin/python setup.py py2app

Running build.sh should compile the app. 运行build.sh应该编译应用程序。 If it does not compile, I have good news -- it's not your fault. 如果它不编译,我有好消息 - 这不是你的错。 Due to glitches in the libraries, you may run into some (or all) of the following: 由于库中的故障,您可能会遇到以下一些(或全部):

Potential Problems If the build script fails, scan the traceback for some of the following keywords: 潜在问题如果构建脚本失败,请扫描回溯以获取以下某些关键字:

pygame not found - basic path problem in py2app. 找不到pygame - py2app中的基本路径问题。 Add... 加...

sys.path.insert(0, os.path.join(os.getcwd(), 'lib', 'python2.6','lib-dynload')) ## Added to fix dynlib bug

after the import statements in boot_app.py in the py2app lib. 在py2app lib中的boot_app.py中的import语句之后。

pythonNone - This appears to be a bug in the macho package where it cannot determine the version number of your python build. pythonNone - 这似乎是macho包中的一个错误,它无法确定python构建的版本号。 To solve this, I added the following lines to build_app.py in py2app. 为了解决这个问题,我在py2app中为build_app.py添加了以下行。

## Add these two lines...
if not info["version"]:
  info["version"] = "2.6"
## Before this line. (line 941 in method copy_python_framework() at time of writing)
pydir = 'python%s'%(info['version'])

No such file or directory...Python.framework/[lib|include] - py2app is simply looking for directories that exist deeper in the file system tree. 没有这样的文件或目录...... Python.framework / [lib | include] - py2app只是在寻找文件系统树中更深层的目录。 Go to the Python.framework directory and symlink up the place... 转到Python.framework目录并在该地方符号链接...

cd /Library/Frameworks/Python.framework
sudo ln -s Versions/Current/include/ include
sudo ln -s Versions/Current/lib lib

That should do it! 应该这样做! - These steps created a compiled app that worked on other intel machines. - 这些步骤创建了一个可在其他intel机器上运行的已编译应用程序

Thank you for posting what you found! 感谢您发布您找到的内容!

I had a similar problem. 我遇到了类似的问题。 I tried various combinations of what you suggested, and isolated the single issue for me to be the bug in boot_app.py which you identify above. 我尝试了你建议的各种组合,并将我的单个问题隔离为你在上面确定的boot_app.py中的错误。

Once I added the one-line fix to boot_app.py which you identify above, everything worked, even using the pre-installed Apple build of python (version 2.6.1). 一旦我将上面标识的boot_app.py添加到单行修复程序中,即使使用预安装的Python版本的Python(版本2.6.1),一切都能正常工作。

I should note that when I say "everything worked," I really mean building a py2app app for actual distribution, ie using the normal command: 我应该注意,当我说“一切正常”时,我的意思是建立一个py2app应用程序进行实际分发,即使用正常的命令:

python setup.py py2app

The "alias" mode. “别名”模式。 ie

python setup.py py2app -A

which the py2app documentation suggests for use during development, still does not work for me (with the same module not found error). py2app文档建议在开发过程中使用,仍然不适合我(使用相同的模块找不到错误)。 But better the actual distribution build working than nothing at all! 但更好的实际分布构建工作比什么都没有! Again, thanks. 再次,谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM