简体   繁体   English

如何将多个文件添加到py2app?

[英]How to add multiple files to py2app?

I have a python script which makes a GUI. 我有一个python脚本,它可以创建一个GUI。 When a button 'Run' is pressed in this GUI it runs a function from an imported package (which I made) like this 当在此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)

When I run the GUI directly from python it all works well and the program writes an output file. 当我直接从python运行GUI时,它运行良好,程序写入一个输出文件。 However, when I make it into an app, the GUI starts but when I press the button nothing happens. 然而,当我进入应用程序时,GUI启动,但是当我按下按钮时没有任何反应。 predictmiP does get included in build/bdist.macosx-10.3-fat/python2.7-standalone/app/collect/, like all the other imports I'm using (although it is empty, but that's the same as all the other imports I have). predictmiP确实包含在build / bdist.macosx-10.3-fat / python2.7-standalone / app / collect /中,就像我正在使用的所有其他导入一样(虽然它是空的,但是和所有其他导入一样我有)。

How can I get multiple python files, or an imported package to work with py2app? 如何获取多个python文件,或导入的包与py2app一起使用?

my setup.py: 我的setup.py:

""" This is a setup.py script generated by py2applet msgstr“”“这是py2applet生成的setup.py脚本

Usage: python setup.py py2app """ 用法: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'],
)

edit: 编辑:

It looked like it worked, but it only works for a little. 它看起来很有效,但它只能起作用。 From my GUI I call 从我的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 looks like this: 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])

This function gets called, makeblastdb which I call through subprocess does output a file. 这个函数被调用,我通过子进程调用的makeblastdb输出一个文件。 However, the program does not continue, 但是,该计划不会继续,

dlg = wx.MessageDialog( self, "werkt"+self.saveOutputField, "werkt", wx.OK)
dlg.ShowModal() # Show it

in the next lines never gets executed. 在下一行中永远不会执行。

py2app (or rather, setup.py) doesn't magically include files, just because you import them in your application code. py2app(或更确切地说,setup.py)并不神奇地包含文件,只是因为您在应用程序代码中导入它们。

From your description it's not quite clear to me where the predictmiP.py file is located, where the mip3.py file is located, where the setup.py file is located, and how the rest of the directory tree looks. 根据您的描述,我不太清楚predictmiP.py文件的位置,mip3.py文件所在的位置,setup.py文件所在的位置以及目录树的其余部分。

So, a few general notes on packaging Python files (see also http://docs.python.org/2.7/distutils/index.html ). 所以,关于打包Python文件的一些一般说明(另见http://docs.python.org/2.7/distutils/index.html )。 If you just have a few files, you can list them explicitly: 如果您只有几个文件,则可以明确列出它们:

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

This would include file1.py and file2.py . 这将包括file1.pyfile2.py If you have lots of files, that gets tedious, of course, so you can tell setup.py to include all Python files it finds, like so: 如果你有很多文件,那当然是繁琐的,所以你可以告诉setup.py包含它找到的所有Python文件,如下所示:

setup(
    package='example',
)

This expects a directory named example , containing an __init__.py , and will include all Python files found there. 这需要一个名为example的目录,其中包含__init__.py ,并将包含在那里找到的所有Python文件。

If you have a different directory layout, eg a src directory containing the Python files, set it like this: 如果您有不同的目录布局,例如包含Python文件的src目录,请将其设置如下:

setup(
    package='example',
    package_dir={'': 'src'}
)

This expects a directory src/example , and includes the Python files below there. 这需要一个目录src/example ,并在那里包含Python文件。

Since your setup.py is not provided, I will guess it does not resemble something like: 由于没有提供你的setup.py,我猜它不会像这样:

from setuptools import setup

OPTIONS = {'packages' : ['predictmiP']}

setup(app=someapp.py, options={'py2app' : OPTIONS},
      setup_requires=['py2app'])

Or maybe you are looking for OPTIONS['includes'] ? 或者您正在寻找OPTIONS['includes'] Or maybe OPTIONS['frameworks'] ? 或者OPTIONS['frameworks']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM