したがって、次のようなディレクトリツリーがあります。
/
setup.py
src/
ui.py
load.py
search.py
parser.py
img.py
obj.py
#..etc
res/
img.py
Setup.py は次のようになります。
#!/usr/bin/env python
import os
import shutil
import sys
import subprocess
import copy
from distutils.core import setup
if "py2app" in sys.argv:
## Move the setup script to the src/ folder, then re-run it
shutil.copy("setup.py", "src")
newArgv = copy.copy(sys.argv)
newArgv[newArgv.index("py2app")] = "rerun"
os.chdir("src")
subprocess.call(["python"] + newArgv)
elif "rerun" in sys.argv:
import py2app
sys.argv[sys.argv.index("rerun")] = "py2app"
setup(
options={
"py2app": {
"packages": "wx",
"site_packages": True
},
},
app=["ui.py"],
package_dir={"": "."})
## Go back up a directory level and copy the build and dist folders up as well
os.chdir('..')
for fldr in ["build", "dist"]:
if os.path.exists(fldr):
shutil.rmtree(fldr)
shutil.move(os.path.join("src", fldr), ".")
## Copy the necessary data directories to their relevant locations in the app file
for fldr in ["xml", "templates", "data"]:
print "Copying %s..." % fldr
shutil.copytree(fldr, os.path.join("dist/ui.app/Contents/", fldr))
os.remove(os.path.join("src", sys.argv[0]))
(私が奇妙な subprocess.call forky を行う理由は、ツリーのルートに setup.py が必要なためですが、すべてのソースは src/ にあります)
を実行するpython setup.py py2app
と完全に終了しますが、ui.app を開くと次のエラーが発生します。
Traceback (most recent call last):
File "/Users/smith/Code/digital-directory/dist/ui.app/Contents/Resources/__boot__.py", line 127, in <module>
_run()
File "/Users/smith/Code/digital-directory/dist/ui.app/Contents/Resources/__boot__.py", line 122, in _run
exec(compile(source, path, 'exec'), globals(), globals())
File "/Users/smith/Code/digital-directory/dist/ui.app/Contents/Resources/ui.py", line 14, in <module>
import load
ImportError: No module named load