Problem using py2app with lxml package

I am trying to use py2app to create a standalone application from some Python scripts. Python uses the "lxml" package, and I found that I have to specify this explicitly in the setup.py file that py2app uses. However, the resulting application program will still not work on machines that did not have lxml installed.

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 causes 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 

The symbol "_xmlSchematronParse" is a library called "libxml2" on which "lxml" depends. The version that comes with Mac OS X preinstalled is not relevant enough for "lxml", so I had to install version 2.7.2 (in / usr / local). py2app is for some reason linked in a version in / Developer / SDKs / MacOSX 10.3.9.sdk / usr / lib. When I run my application as a Python script, although the correct version is found. (I checked it just now, hiding version 2.7.2.)

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

+6
python lxml py2app
source share
4 answers

Found. py2app has a "framework" parameter that allows you to specify frameworks as well as dylib. Now the setup.py file 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']) 

and it fixed him.

Thanks for the suggestions that brought me here.

+11
source share

------------- Edit --------------
libxml2 is standard in the python.org Python version. This is not a standard version of Apple Python. Make sure py2app uses the correct version of Python or install libxml2 and libxslt on your Mac.

+1
source share

I have no experience with the combination of lxml and py2app specifically, but I had problems with py2app that did not compile modules that were not explicitly imported. For example, I had to explicitly include modules that are imported via __import__() , for example:

 OPTIONS['includes'] = [filename[:-3].replace('/', '.') for filename \ in glob.glob('path/to/*.py')] 

Maybe this will also help in your case insert an explicit from lxml import etree somewhere in your code?

+1
source share

I just tried my application (uses py2app and lxml with the same setup) on another Mac without development libraries installed, and it works, so there should be something wrong on your system. I assume that py2app is choosing the wrong version of libxml2 (I see that it comes with the iPhone SDK, for example, which is probably not the version you want).

Mine, as a whole python toolchain, comes from MacPorts, the sum of md5 of the last libxml2.2.dylib (the one that ends with my .app) is 863c7208b6c34f116a2925444933c22a on my system.

+1
source share

All Articles