Problem using py2app with the lxml package

后端 未结 4 849
迷失自我
迷失自我 2021-02-09 21:54

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 ex

相关标签:
4条回答
  • 2021-02-09 22:29

    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'])
    

    and that's fixed it.

    Thanks for the suggestions that led me here.

    0 讨论(0)
  • 2021-02-09 22:36

    I just tried my app (uses py2app and lxml, with a similar setup) on another Mac without development libraries installed, and it works, so there must be something wrong in your system. My guess is that py2app picks the wrong version of libxml2 (I see it comes bundled with the iPhone SDK for example, which is probably not the version you want).

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

    0 讨论(0)
  • 2021-02-09 22:37

    I have no experience with the combination of lxml and py2app specifically, but I've had issues with py2app not picking up modules that were not explicitly imported. For example, I had to explicitly include modules that are imported via __import__(), like this:

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

    Maybe it also helps in your case to insert an explicit from lxml import etree somewhere in your code?

    0 讨论(0)
  • 2021-02-09 22:44

    ------------- Edit--------------
    libxml2 is standard in the python.org version of Python. It is not standard in Apple's version of Python. Make sure py2app is using the right version of Python, or install libxml2 and libxslt on your Mac.

    0 讨论(0)
提交回复
热议问题