ImportError:没有使用py2app命名为PIL的模块

时间:2016-09-22 22:15:54

标签: python py2app

我正在尝试从python文件创建一个mac应用程序。我遇到了“ImportError:No module named PIL”错误。请注意,从命令行运行时,已安装PIL并且此脚本正确运行。我想把它变成一个osx应用程序。当我运行从py2app创建的osx应用程序时,我收到以下错误。

我试过了:

'includes': ['PIL']

'packages': ['PIL']

'modules': ['PIL']

如何正确包含PIL?

setup.py

from setuptools import setup

APP = ['Sandwich.py']
APP_NAME = "asdfasdf"
DATA_FILES = []
OPTIONS = {
    'argv_emulation': True,
    'iconfile': 'app.png',
    'includes': ['PIL']
    } 

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

Sandwich.py​​

import sys
import time
from PIL import ImageGrab

while(1):
    print "Chekcing in"
    time.sleep(1)

错误

9/22/16 3:13:23.736 PM PAssist[28192]: Traceback (most recent call last):
9/22/16 3:13:23.736 PM PAssist[28192]:   File "/Users/joeyz/Projects/SandwichApp/dist/PAssist.app/Contents/Resources/__boot__.py", line 351, in <module>
9/22/16 3:13:23.736 PM PAssist[28192]:     _run()
9/22/16 3:13:23.736 PM PAssist[28192]:   File "/Users/joeyz/Projects/SandwichApp/dist/PAssist.app/Contents/Resources/__boot__.py", line 336, in _run
9/22/16 3:13:23.736 PM PAssist[28192]:     exec(compile(source, path, 'exec'), globals(), globals())
9/22/16 3:13:23.736 PM PAssist[28192]:   File "/Users/joeyz/Projects/SandwichApp/dist/PAssist.app/Contents/Resources/Sandwich.py", line 3, in <module>
9/22/16 3:13:23.736 PM PAssist[28192]:     from PIL import ImageGrab
9/22/16 3:13:23.736 PM PAssist[28192]: ImportError: No module named PIL
9/22/16 3:13:23.796 PM PAssist[28192]: PAssist Error
9/22/16 3:13:23.796 PM PAssist[28192]: 2016-09-22 15:13:23.796 PAssist[28192:10044666] PAssist Error

1 个答案:

答案 0 :(得分:0)

您可以在安装程序中使用install_requires关键字。这具有安装软件包的额外好处。在您的情况下,我将使用install_requires=['pillow'],pip将在安装过程中自动抓住枕头。您仍然可以在上面指定的软件包中使用PIL。得到了问题的答案:[39649714]

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
    install_requires=['pillow'],
)