在kivy中超过了最大递归深度,但仅在打包时超过了,而在python中开发应用程序时则没有 [英] Maximum recursion depth exceeded in kivy but only when packaging, not when developing the app in python

查看:86
本文介绍了在kivy中超过了最大递归深度,但仅在打包时超过了,而在python中开发应用程序时则没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打包一个需要多次导入的应用,其中包括matplotlib.pyplot

I am trying to pack an app that requires several imports, among those matplotlib.pyplot

kivy应用程序(已简化,但仍在运行)是:

The kivy app (simplified, but still working) is:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
import matplotlib.pyplot


Builder.load_string("""
<MyWidget>:
    id: my_widget
    FileChooserIconView:
        id: filechooser
        on_selection: my_widget.selected(filechooser.selection)
    Image:
        id: image
        source: ""
""")


class MyWidget(BoxLayout):

    def selected(self,filename):
        self.ids.image.source = filename[0]


class MyApp(App):
    def build(self):
        return MyWidget()


if __name__ == '__main__':
    MyApp().run()

该应用程序在使用spyder的python中完美运行.

This app works perfectly in python using spyder.

但是,当我尝试将其打包为独立的kivy应用程序时,它给了我错误,超过了最大递归深度.

However, when I try to pack it as an independent kivy app it gives me error maximum recursion depth exceeded.

我很惊讶,不知道是什么原因,因为:

I am surprised and I do not know what the problem is because:

1.应用程序中没有递归函数.

1.There are no recursive functions in the app.

2.在开发和测试python spyder时可以完美地工作,唯一的问题是在包装过程中.

2.Works perfectly in python spyder while developing it and testing it, the only problem is during packaging.

3.我尝试了多种选择,包括注释了几个部分,最令人惊讶的是,当我注释了导入matplotlib.pyplot应用程序包时,它很好.但是,我需要此应用程序使用matplotlib.pyplot,因此将其取出不是一种选择.

3.I have tried multiple options, including commenting out several portions and, most surprising, when I comment out the import matplotlib.pyplot the app packages well. However I need matplotlib.pyplot for this app so taking it out is not an option.

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
#import matplotlib.pyplot


Builder.load_string("""
<MyWidget>:
    id: my_widget
    FileChooserIconView:
        id: filechooser
        on_selection: my_widget.selected(filechooser.selection)
    Image:
        id: image
        source: ""
""")


class MyWidget(BoxLayout):

    def selected(self,filename):
        self.ids.image.source = filename[0]


class MyApp(App):
    def build(self):
        return MyWidget()


if __name__ == '__main__':
    MyApp().run()

上面的代码可以很好地工作和打包.

The above code works and packages well.

可以导入到kivy应用程序的文件大小是否有一定限制?我已经尝试使用sys.setrecursionlimit(high number)增加递归限制,但这不是解决此问题的方法. 我真的迷路了.任何见解表示赞赏.

Is it that there is some limit of the size of the files one can import to a kivy app? I have already tried to increase the recursion limit with sys.setrecursionlimit(high numbers) but it is not a solution to this problem. I am really lost. Any insight appreciated.

谢谢

编辑2/4/2019: 有人提出这样的问题: pyinstaller创建EXE RuntimeError :调用Python对象时超出了最大递归深度,并且重复了此问题.尽管这绝对是一个相关的问题,并且很有帮助,但是在创建kivy包的第一阶段,我的错误发生了: python -m PyInstaller --name touchtracer examples-path \ demo \ touchtracer \ main.py

Edit 2/4/2019: It has been suggested that the question: pyinstaller creating EXE RuntimeError: maximum recursion depth exceeded while calling a Python object is a duplicate and answers this question. Although this is definitively a related question and is helpful, my error occurs in the first stage of the creation of the kivy package: python -m PyInstaller --name touchtracer examples-path\demo\touchtracer\main.py

推荐答案

非常感谢所有尝试提供帮助的人. 我找到了答案,希望它对尝试创建kivy包的其他人有所帮助,并且在导入python模块时出现问题.

Thank you so MUCH to everybody who tried to help. I found an answer and I hope it helps other people who tries to create a kivy package and there is a problem importing python module(s).

一旦您准备好打包main.py脚本:

Once you have your main.py script ready to package:

1.从以下说明开始

https://kivy.org/doc/stable/guide/packaging-windows.html

并执行第一步:

python -m PyInstaller --name touchtracer examples-path\demo\touchtracer\main.py

这将为您提供maximum recursion depth exceeded的错误或最初给您的任何错误.不用担心.此步骤的目的是创建一个初始的spec文件.

This will give you the error of maximum recursion depth exceeded or whatever error this gives to you originally. No worries. The purpose of this step is to create an initial spec file.

2.打开spec文件,并添加

2.Open the spec file and add all the extras that the kivy instructions give you at

https://kivy.org/doc/stable/guide/packaging-windows.html

即:

from kivy.deps import sdl2, glew
Tree('examples-path\\demo\\touchtracer\\'),
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],

3.除此之外,在spec文件的开头添加以下内容:

3.In addition to that, add at the beginning of the spec file the following:

import sys
sys.setrecursionlimit(5000) # (or some big number)

4.还要在您可能需要的隐藏导入中添加任何导入.

4.Also add any imports in the hidden imports that you might need.

hiddenimports=[] # change to (example importing pandas and matplotlib) hiddenimports=['pandas', 'matplotlib']

5.只需按照

https://kivy.org/doc/stable/guide/packaging-windows.html

即:

python -m PyInstaller touchtracer.spec

并构建您的应用

这篇关于在kivy中超过了最大递归深度,但仅在打包时超过了,而在python中开发应用程序时则没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆