我有一个制作GUI的python脚本。当在此GUI中按下“运行”按钮时,它将像这样从导入的包(由我制作)中运行功能

from predictmiP import predictor
class MiPFrame(wx.Frame):
    [...]
    def runmiP(self, event):
         predictor.runPrediction(self.uploadProtInterestField.GetValue(), self.uploadAllProteinsField.GetValue(), self.uploadPfamTextField.GetValue(), \
                   self.edit_eval_all.Value, self.edit_eval_small.Value, self.saveOutputField)

当我直接从python运行GUI时,一切正常,程序将写入输出文件。但是,当我将其放入应用程序时,GUI会启动,但是当我按下按钮时,什么也不会发生。就像我正在使用的所有其他导入一样,预报miP确实包含在build/bdist.macosx-10.3-fat/python2.7-standalone/app/collect/中(尽管它是空的,但与所有其他导入相同我有)。

如何获取多个python文件或导入的包以与py2app一起使用?

我的setup.py:

“”
这是由py2applet生成的setup.py脚本

用法:
python setup.py py2app
“”
from setuptools import setup

APP = ['mip3.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

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

编辑:

看起来像它有用,但只起作用了一点。从我的GUI中,我打电话
 blast.makeBLASTdb(self.uploadAllProteinsField.GetValue(), 'allDB')

 # to test if it's working
 dlg = wx.MessageDialog( self, "werkt"+self.saveOutputField, "werkt", wx.OK)
 dlg.ShowModal() # Show it
 dlg.Destroy() # finally destroy it when finished.

blast.makeBLASTdb看起来像这样:
def makeBLASTdb(proteins_file, database_name):
    subprocess.call(['/.'+os.path.realpath(__file__).rstrip(__file__.split('/')[-1])+'blast/makeblastdb', '-in', proteins_file, '-dbtype', 'prot', '-out', database_name])

该函数被调用,我通过子进程调用的makeblastdb确实输出文件。但是,该程序不会继续,
dlg = wx.MessageDialog( self, "werkt"+self.saveOutputField, "werkt", wx.OK)
dlg.ShowModal() # Show it

在接下来的几行中,永远不会执行。

最佳答案

py2app(或更确切地说,setup.py)并没有神奇地包含文件,只是因为您将它们导入了应用程序代码。

从您的描述中,我不太清楚predictmiP.py文件的位置,mip3.py文件的位置,setup.py文件的位置以及其余目录树的外观。

因此,有关打包Python文件的一些常规说明(另请参见http://docs.python.org/2.7/distutils/index.html)。如果只有几个文件,则可以明确列出它们:

setup(
    py_modules=['file1', 'file2']
)

这将包括file1.pyfile2.py。当然,如果您有很多文件,那会很乏味,因此您可以告诉setup.py包括它找到的所有Python文件,如下所示:
setup(
    package='example',
)

这需要一个名为example的目录,其中包含一个__init__.py,并将包含在此找到的所有Python文件。

如果您使用其他目录布局,例如包含Python文件的src目录,如下设置:
setup(
    package='example',
    package_dir={'': 'src'}
)

这需要一个src/example目录,并在下面包含Python文件。

10-06 10:14
查看更多