ArgumentError:参数3:<class'TypeError'>:错误的类型

时间:2019-07-20 02:49:15

标签: python anaconda kivy

我正在通过nimiconda在win10上测试kivy。

每当我第二次运行(按miniconda上的F5,与anaconda相同)第二次执行kivy代码时,consel都会抛出“ ArgumentError:argument 3 ::错误的类型”

我用Miniconda3测试了kivy代码(也在Anaconda3中测试了它,出现了同样的问题),每次我第一次按F5键,代码都能正常运行,并且kivy界面正常出现,如下:

runfile('C:/Users/38477/.spyder-py3/temp.py', wdir='C:/Users/38477/.spyder-py3')

[INFO   ] [Logger      ] Record log in C:\Users\38477\.kivy\logs\kivy_19-07-20_1.txt
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "G:\Miniconda3\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "G:\Miniconda3\pythonw.exe"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.0.0 - Build 10.18.10.4885'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) HD Graphics 4000'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 0
[INFO   ] [GL          ] Shading version <b'4.00 - Build 10.18.10.4885'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [WindowSDL   ] exiting mainloop and closing.
[INFO   ] [Base        ] Leaving application in progress...

但是在清空kivy界面后,按F5键将报告以下错误。

runfile('C:/Users/38477/.spyder-py3/temp.py', wdir='C:/Users/38477/.spyder-py3')
[INFO   ] [Base        ] Start application main loop
[ERROR  ] [Base        ] No event listeners have been created
[ERROR  ] [Base        ] Application will leave
[INFO   ] [Base        ] Leaving application in progress...
[INFO   ] [Base        ] Leaving application in progress...
Traceback (most recent call last):

File "<ipython-input-2-83710e3ec7f9>", line 1, in <module>
runfile('C:/Users/38477/.spyder-py3/temp.py', wdir='C:/Users/38477/.spyder-py3')

File"G:\Miniconda3\lib\sitepackages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
   execfile(filename, namespace)

File "G:\Miniconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

 File "C:/Users/38477/.spyder-py3/temp.py", line 15, in <module>
   TestApp().run()

 File "G:\Miniconda3\lib\site-packages\kivy\app.py", line 855, in run
   runTouchApp()

 File "G:\Miniconda3\lib\site-packages\kivy\base.py", line 506, in runTouchApp
   stopTouchApp()

 File "G:\Miniconda3\lib\site-packages\kivy\base.py", line 521, in stopTouchApp
   EventLoop.close()

 File "G:\Miniconda3\lib\site-packages\kivy\base.py", line 172, in close
   self.stop()

 File "G:\Miniconda3\lib\site-packages\kivy\base.py", line 184, in stop
   provider.stop()

 File "G:\Miniconda3\lib\site-packages\kivy\input\providers\wm_pen.py", line 111, in stop
   SetWindowLong_WndProc_wrapper(self.hwnd, self.old_windProc)

 File "G:\Miniconda3\lib\site-packages\kivy\input\providers\wm_common.py", line 122, in _closure
   oldAddr = func(hWnd, GWL_WNDPROC, cast(wndProc, c_void_p).value)

ArgumentError: argument 3: <class 'TypeError'>: wrong type

这是我从https://kivy.org/#home获得的测试代码

from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
    def build(self):
        return Button(text='Hello World')

TestApp().run()

重新启动内核是一种可行的方法,但这意味着我必须在运行代码后每次都重新启动内核。是正常的吗?

环境

active environment : base
active env location : G:\Miniconda3
shell level : 1
user config file : C:\Users\38477\.condarc
populated config files :
conda version : 4.7.9
conda-build version : not installed
python version : 3.7.3.final.0
virtual packages : __cuda=9.1
base environment : G:\Miniconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
 package cache : G:\Miniconda3\pkgs
                           C:\Users\38477\.conda\pkgs
                          C:\Users\38477\AppData\Local\conda\conda\pkgs
       envs directories : G:\Miniconda3\envs
                          C:\Users\38477\.conda\envs
                          C:\Users\38477\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/4.7.9 requests/2.21.0 CPython/3.7.3 Windows/10 Windows/10.0.17134
administrator : False
netrc file : None
offline mode : False

2 个答案:

答案 0 :(得分:4)

我曾经遇到过同样的问题,如果您使用的是spyder,则有3种解决方案:

1。每次要运行代码时,关闭并再次打开spyder

2.Consotools> preferences> run>在外部系统终端中执行,然后单击“确定”。 (使用F5运行)

3。控制台>使用F5或F9运行应用程序之前,“重新启动内核”

答案 1 :(得分:1)

您不能每次都在相同的python执行中运行Kivy应用程序,这就是为什么需要重新启动内核的原因。我没有用过miniconda,但我想您已经用过Spyder。为了在Spyder中顺利运行Kivy应用程序,您可以在外部系统中启用执行。
转到工具>>首选项。在首选项对话框中,转到“运行”选项卡,然后启用“在外部系统终端中执行”。
或者您可以在每次执行之前重新启动内核。我想那会令人不安。
希望对您有所帮助。