简体   繁体   English

Py2app找不到工作目录

[英]Py2app is not finding the working directory

I keep get this error when i run my py2app. 当我运行py2app时,我一直收到此错误。 It works when i do python app.py and when it runs as a terminal, however it doesnt work when its built to work as an py2app 它在我做python app.py并作为终端运行时起作用,但是当其构建为py2app时它不起作用

在此处输入图片说明

It's a scrapy project. 这是一个令人毛骨悚然的项目。

app.py app.py

import os
from subprocess import call


def main():
    cw = os.getcwd()
    path = '/scrape'
    cwd = cw + os.path.join(path)
    ourPath = ['scrapy','crawl', 'yellow']
    name = "yellow"
    call(["scrapy", "crawl", "{0}".format(name)], cwd=cwd)

if __name__ == "__main__" :
    main()

在此处输入图片说明

The scrape package isn't included in /Contents/Resources folder. scrape不包含在/Contents/Resources文件夹中。 Since app.py doesn't include any names from the scrape package, the module graph that is constructed when building the application bundle doesn't consist it. 由于app.py不包含scrape包中的任何名称,因此在构建应用程序捆绑包时构建的模块图不包含它。

Build procedure can be updated to include the scrape package using the --package option passed to py2app . 使用传递给py2app--package选项,可以更新构建过程以包括scrape软件包。 [1] [1]
However when --package option is provided, scrapy package will be copied in Contents/Resources/lib/python2.X/ . 但是,当提供--package选项时, scrapy软件包将被复制到Contents/Resources/lib/python2.X/ [2] [2]
This means that you'll have to resolve the directory of the subprocess command for run in to this new path. 这意味着您必须解析要在此新路径中运行的subprocess命令的目录。

A better way to go about this is to run the scraper directly via the Crawler API and not as a subprocess command where that is feasible. 更好的方法是直接通过Crawler API运行刮板,而不是在可行的情况下将其作为子流程命令。 [3] With the approach, py2app builds the module graph to include necessary code from scrape package. [3]通过这种方法,py2app构建模块图以包括来自scrape包的必要代码。

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

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