python - 使用 py2app 资源目录

标签 python py2app

我有一些目录敏感的数据文件。如何将它们添加到我的 .app 包中?

py2app 给出的文档都没有说明如何具体执行此操作。然而,在网上查了一下,我发现可以使用元组来添加特定目录结构中的资源。我假设顺序是 (directoryInResourceFolder, pathToFile)

当我尝试这样做时,出现以下错误:

error: No such file or directory: m

我不知道为什么会这么说,因为我的元组都不是 m。这是我生成的元组列表:

[('src/math_patterns', 'math_patterns/_BordersSlashes.txt'), ('src/math_patterns', 'math_patterns/_codes.txt'), ('src/math_patterns', 'math_patterns/_Dollars.txt'), ('src/math_patterns', 'math_patterns/_Fences.txt'), ('src/math_patterns', 'math_patterns/_Final.txt'), ('src/math_patterns', 'math_patterns/_Fractions.txt'), ('src/math_patterns', 'math_patterns/_FunctionsLimits.txt'), ('src/math_patterns', 'math_patterns/_Integrals.txt'), ('src/math_patterns', 'math_patterns/_Numbers.txt'), ('src/math_patterns', 'math_patterns/_PowersPrimes.txt'), ('src/math_patterns', 'math_patterns/_SoftFractions.txt'), ('src/math_patterns', 'math_patterns/_test.txt'), ('src/math_patterns', 'math_patterns/_Trig.txt'), ('src/math_patterns', 'math_patterns/_Unicodes.txt'), ('src/math_patterns', 'math_patterns/_Vocab.txt'), ('src/math_patterns', 'math_patterns/Calculus.txt'), ('src/math_patterns', 'math_patterns/General.txt'), ('src/math_patterns', 'math_patterns/Geometry and Trigonometry.txt'), ('src/math_patterns', 'math_patterns/Linear Algebra.txt'), ('src/math_patterns', 'math_patterns/Logic.txt'), ('src/math_patterns', 'math_patterns/Statistics.txt')]

这是我正在使用的 setup.py:

from setuptools import setup
import os

APP = ['main.py']

# Prepare all of the resources that I would need
RESOURCES = []

p = 'math_patterns'
files = []
for f in os.listdir(p):
    fullPath = os.path.join(p, f)
    if os.path.isfile(fullPath):
        files.append(('src/math_patterns', fullPath))
RESOURCES.extend(files)

PACKAGES = ['lxml']

INCLUDES = ['sip']

OPTIONS = {'argv_emulation': True,
           'packages': PACKAGES,
           'includes': INCLUDES,
           'resources': RESOURCES}

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

感谢您花时间查看此内容!

-- 编辑

使用绝对路径可以消除该特定错误。但现在它尝试在 math_patterns 目录中创建 .apdisk,这会抛出以下错误:

error:/.DocumentRevisions-V100: Permission denied

最佳答案

好吧,在意识到 .app 只是一个目录之后,我最终使用 bash 脚本将文件插入到正确的位置。谁需要 py2app 来实现这个目的?

这确实有点傻。

关于python - 使用 py2app 资源目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18108356/

相关文章:

python - 模块 "duck typing"有陷阱吗?

python - 如何使用 virtualenv 管理来自 vim 插件的 python 依赖项?

python - Python 链式属性访问中的无传播

python - OSX 10.6.3 上的 Python2.6 未找到 Evt.TickCount()

python - 更改 Mac OS 下除终端以外的应用程序的 Python 路径

python - 无法正确识别字母

python - Py2app:不允许操作

python - py2app 错误 : in find_needed_modules TypeError: 'NoneType' object has no attribute '__getitem__'

python - 使用 py2app 时,有没有办法自定义显示的回溯对话框? (或者显示不同的 Cocoa 对话框?)

python - Lion 上的 py2app 正在创建没有 python 框架或资源的空应用程序