2

我有一些目录敏感的数据文件。如何将它们添加到我的 .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'],
)

感谢您花时间看这个!

- 编辑

使用绝对路径使该特定错误消失。但现在它试图.apdiskmath_patterns目录中创建一个,它会吐出以下错误:

error:/.DocumentRevisions-V100: Permission denied
4

2 回答 2

5

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

这有点傻,真的。

于 2013-08-07T17:12:15.477 回答
0
$ python setup.py py2app

不是

$ python setup.py py2app -A
于 2014-09-09T17:32:44.623 回答