2012-12-18 29 views
1

所以我有一个目录树是这样的:Py2app导入错误的用户创建的模块

/ 
    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因为要求在树的根目录中有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 

回答