[英]Why am I getting the Import error in python, when I have pip installed every single module required for my App
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import Gridlayout
from kivy.uix.textinput import TextInput
class MyGrid(GridLayout):
def __init__(self, **kwargs):
super(MyGrid, self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text="Name: "))
self.name = TextInput(multiline=False)
self.add_widget(self.name)
class MyApp(App):
def build(self):
return MyGrid()
if __name__ == "__main__":
MyApp().run()
After running this I am getting the result this:运行此之后,我得到以下结果:
>>>
= RESTART: C:\Users\skkar\Desktop\adi\Python Files\Telgram Bot\Python\App for Telegram Bot\Adot Telegrm Bot App.py
[INFO ] [Logger ] Record log in C:\Users\skkar\.kivy\logs\kivy_21-04-07_13.txt
[INFO ] [deps ] Successfully imported "kivy_deps.gstreamer" 0.3.2
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO ] [Kivy ] v2.0.0
[INFO ] [Kivy ] Installed at "C:\Users\skkar\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\__init__.py"
[INFO ] [Python ] v3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Users\skkar\AppData\Local\Programs\Python\Python39\pythonw.exe"
[INFO ] [Factory ] 186 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
Traceback (most recent call last):
File "C:\Users\skkar\Desktop\adi\Python Files\Telgram Bot\Python\App for Telegram Bot\Adot Telegrm Bot App.py", line 4, in <module>`
from kivy.uix.gridlayout import Gridlayout
ImportError: cannot import name 'Gridlayout' from 'kivy.uix.gridlayout' (C:\Users\skkar\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\gridlayout.py)
Why am I getting this?为什么我会得到这个? When ever I run it I get this only.
当我运行它时,我只会得到这个。 And nothing else.
没有别的了。
Please tell and help me with my code!请告诉我的代码并帮助我!
Regards K1NG_C0D3R_AD0T问候 K1NG_C0D3R_AD0T
Use GridLayout, with a capital L使用 GridLayout,大写 L
from kivy.uix.gridlayout import GridLayout
You can see in the error message that it cannot import "Gridlayout" because the actual name is "GridLayout".您可以在错误消息中看到它无法导入“Gridlayout”,因为实际名称是“GridLayout”。 I think this will fix your issue.
我认为这将解决您的问题。
Use this:用这个:
from kivy.uix.gridlayout import GridLayout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.