本文介绍了将py2app与lxml包一起使用时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用"py2app"从某些Python脚本生成独立的应用程序. Python使用'lxml'包,我发现我必须在'py2app'使用的setup.py文件中明确指定此包.但是,生成的应用程序仍然无法在未安装'lxml'的计算机上运行.

I am trying to use 'py2app' to generate a standalone application from some Python scripts. The Python uses the 'lxml' package, and I've found that I have to specify this explicitly in the setup.py file that 'py2app' uses. However, the resulting application program still won't run on machines that haven't had 'lxml' installed.

我的Setup.py看起来像这样:

My Setup.py looks like this:

from setuptools import setup

OPTIONS = {'argv_emulation': True, 'packages' : ['lxml']}

setup(app=[MyApp.py],
      data_files=[],
      options={'py2app' : OPTIONS},
      setup_requires=['py2app'])

运行该应用程序将产生以下输出:

Running the application produces the following output:

MyApp Error
An unexpected error has occurred during execution of the main script
ImportError: dlopen(/Users/ake/XXXX/XXXX/MyApp.app/Contents/Resources/lib/python2.5/lxml/etree.so, 2): Symbol not found: _xmlSchematronParse
Referenced from: /Users/ake/XXXX/XXXX/MyApp.app/Contents/Resources/lib/python2.5/lxml/etree.so
Expected in: dynamic lookup

符号"_xmlSchematronParse"来自"lxml"所依赖的名为"libxml2"的库. Mac OS X上预装的版本对于'lxml'来说还不够最新,因此我必须安装2.7.2版(在/usr/local中).出于某些原因,py2app链接到/Developer/SDKs/MacOSX10.3.9.sdk/usr/lib中的版本.当我将应用程序作为Python脚本运行时,会找到正确的版本. (我刚才通过隐藏2.7.2版本对此进行了检查.)

The symbol '_xmlSchematronParse' is from a library called 'libxml2' that 'lxml' depends on. The version that comes preinstalled with Mac OS X isn't up to date enough for 'lxml', so I had to install version 2.7.2 (in /usr/local). py2app, for some reason, is linking in the version in /Developer/SDKs/MacOSX10.3.9.sdk/usr/lib. When I run my application as a Python script though, the correct version is found. (I checked this just now by hiding the 2.7.2 version.)

所以我现在的问题是,如何告诉py2app在哪里寻找库?

So my question now is, how can I tell py2app where to look for libraries?

推荐答案

找到了它. py2app有一个'frameworks'选项,可让您指定框架以及dylib.我的setup.py文件现在看起来像这样:

Found it. py2app has a 'frameworks' option to let you specify frameworks, and also dylibs. My setup.py file now looks like this:

from setuptools import setup

DATA_FILES = []
OPTIONS = {'argv_emulation': True,
           'packages' : ['lxml'],
           'frameworks' : ['/usr/local/libxml2-2.7.2/lib/libxml2.2.7.2.dylib']
          }

setup(app=MyApp.py,
      data_files=DATA_FILES,
      options={'py2app' : OPTIONS},
      setup_requires=['py2app'])

这已经解决了.

感谢引导我来到这里的建议.

Thanks for the suggestions that led me here.

这篇关于将py2app与lxml包一起使用时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 07:34