ModuleNotFoundError: no module name kivy
See original GitHub issueHi, When I try running the code below and use the instructions here to produce an ios app, I run into a ModuleNotFoundError: no module name kivy (line 1) and the app closes abruptly.
`from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import ScreenManager, Screen from kivy.animation import Animation from hoverable import HoverBehavior from kivy.uix.image import Image from kivy.uix.behaviors import ButtonBehavior import json, glob from datetime import datetime from pathlib import Path import random
Builder.load_file(“design.kv”)
class LoginScreen(Screen): def sign_up(self): self.manager.current = “sign_up_screen” self.manager.transition.direction = “up” def login(self, user, passw): with open(“users.json”) as file: users = json.load(file) if user in users and users[user][“password”]==passw: self.manager.transition.direction = “left” self.manager.current = “login_screen_success” else: self.ids.login_wrong.text = “Check again. Password or username wrong.”
def go_to_reset(self):
self.manager.current = "forgot_password"
self.manager.transition.direction = "down"
class RootWidget(ScreenManager): pass
class SignUpScreen(Screen): def add_user(self, uname, pword): with open(“users.json”) as file: users = json.load(file) users[uname] = {“username”: uname, “password”: pword, “created”: datetime.now().strftime(“%Y-%M-%D %H-%S-%M”)}
with open("users.json", "w") as file:
json.dump(users, file)
self.manager.current = "sign_up_screen_success"
self.manager.transition.direction = "left"
def back(self):
self.manager.current = "login_screen"
self.manager.transition.direction = "down"
class SignUpScreenSuccess(Screen): def go_to_login(self): self.manager.transition.direction = “left” self.manager.current = “login_screen”
class LoginScreenSuccess(Screen): def log_out(self): self.manager.transition.direction = “right” self.manager.current = “login_screen”
def get_quote(self, feel):
feel = feel.lower()
available_feelings = glob.glob("quotes/*txt")
available_feelings = [Path(filename).stem for filename in available_feelings]
if feel in available_feelings:
with open(f"quotes/{feel}.txt") as file:
quotes = file.readlines()
self.ids.quote.text = random.choice(quotes)
else:
self.ids.quote.text = "Try another emotion, hombre"
class ForgotPassword(Screen): def back(self): self.manager.current = “login_screen” self.manager.transition.direction = “up” def reset_password(self, uname1, pword2): with open(“users.json”)as file: users = json.load(file) users[uname1] = {“username”: uname1, “password”: pword2, “created”: datetime.now().strftime(“%Y-%M-%D %H-%S-%M”)} with open(“users.json”, “w”) as file: if users[uname1][“username”] == uname1: users[uname1][“password”].replace(pword2, pword2) json.dump(users, file) self.manager.transition.direction = “left” self.manager.current = “forgot_password_success” else: self.ids.no_user.text = “Username not found. Try again or sign up again.”
class ForgotPasswordSuccess(Screen): def log_in_reset(self): self.manager.transition.direction = “left” self.manager.current = “login_screen”
class ImageButton(ButtonBehavior, HoverBehavior, Image): pass
class MainApp(App): def build(self): return RootWidget()
if name == “main”: MainApp().run()`
'<LoginScreen>: GridLayout: cols: 1 GridLayout: cols: 1 padding: 15, 15 spacing: 20, 20 Label: text: “User Login” font_size: “20sp” TextInput: id: username hint_text: “Username” TextInput: id: password password: True hint_text: “Password” RelativeLayout: Button: text: “Login” size_hint: 0.3, 0.5 on_press: root.login(root.ids.username.text, root.ids.password.text) pos_hint: {“center_x”: 0.5, “center_y”: 0.6} Label: id: login_wrong text: “” GridLayout: cols: 2 size_hint: 0.2, 0.2 padding: 10, 10 spacing: 10, 0 Button: text: “Forgot password?” background_color: 1,1,1,0 opacity: 1 if self.state == “normal” else 0.5 color: 0.1, 0.7, 1, 1 on_press: root.go_to_reset() Button: text: “Sign Up” background_color: 1,1,1,0 opacity: 1 if self.state == “normal” else 0.5 color: 0.1, 0.7, 1, 1 on_press: root.sign_up()
<SignUpScreen>: GridLayout: cols: 1 GridLayout: cols: 1 padding: 15, 15 spacing: 20, 20 Label: text: “Sign up” font_size: “20sp” TextInput: id: username hint_text:“Username” TextInput: id: password hint_text: “Password” GridLayout: cols: 2 size_hint: 0.2, 0.2 padding: 10, 10 spacing: 10, 0 Button: text: “Back” on_press: root.back() background_color: 1,1,1,0 opacity: 1 if self.state == “normal” else 0.5 color: 0.1, 0.7, 1, 1 Button: text: “Submit” on_press: root.add_user(root.ids.username.text, root.ids.password.text) background_color: 1,1,1,0 opacity: 1 if self.state == “normal” else 0.5 color: 0.1, 0.7, 1, 1
<SignUpScreenSuccess>: GridLayout: cols: 1 Label: text: “Sign Up Successful!” font_size: “20sp” Button: text: “Login Page” on_press: root.go_to_login() background_color: 1,1,1,0 opacity: 1 if self.state == “normal” else 0.5 color: 0.1, 0.7, 1, 1 pos_hint: {“center_x”: 0.5, “center_y”: 0}
<LoginScreenSuccess>: GridLayout: cols: 1 padding: 30, 30 spacing: 30, 30 RelativeLayout: ImageButton: on_press: root.log_out() source: “logout_hover.png” if self.hovered else “logout_nothover.png” size_hint: 0.35, 0.35 pos_hint: {“center_x”: 0.93, “center_y”: 0.8} Label: text: “How do you feel?” TextInput: id: feeling hint_text: “Things to try: happy, sad, unloved” Button: text: “Consider this” on_press: root.get_quote(root.ids.feeling.text) ScrollView: Label: id: quote text: “” text_size: self.width, None size_hint_y: None height: self.texture_size[1]
<ForgotPassword> GridLayout: cols: 1 GridLayout: cols: 1 padding: 15, 15 spacing: 20, 20 Label: text: "Reset Password" font_size: "20sp" TextInput: id: username hint_text: "Enter username" TextInput: id: password password: True hint_text: "Enter new password" Label: id: no_username text: "" GridLayout: cols: 2 size_hint: 0.2, 0.2 padding: 10, 10 spacing: 10, 0 Button: text: "Back" background_color: 1,1,1,0 opacity: 1 if self.state == "normal" else 0.5 color: 0.1, 0.7, 1, 1 on_press: root.back() Button: text: "Reset" background_color: 1,1,1,0 opacity: 1 if self.state == "normal" else 0.5 color: 0.1, 0.7, 1, 1 on_press: root.reset_password(root.ids.username.text, root.ids.password.text) <ForgotPasswordSuccess> GridLayout: cols: 1 Label: text: "Sign Up Successful!" font_size: "20sp" size_hint: 0.2, 0.2 Button: text: "Login Page" on_press: root.log_in_reset() size_hint: 0.2, 0.2<RootWidget>: LoginScreen: name: “login_screen” SignUpScreen name: “sign_up_screen” SignUpScreenSuccess name: “sign_up_screen_success” LoginScreenSuccess: name: “login_screen_success” ForgotPassword name: “forgot_password” ForgotPasswordSuccess name: “forgot_password_success”’
I followed the instructions in this repo. Could someone please share what could be going wrong?
Many thanks, Jaspal
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (1 by maintainers)
Top GitHub Comments
What you did didn’t work for me either. So I cloned the repo and followed those instructions. I had to edit
toolchain.py
because I was having some issues with the original one. But here’s what I did:Section 1
#! /usr/bin/env python3
to the beginning of the file.virtualenv venv
if you want to. You might need to runpip install virtualenv
to install thevirtualenv
tool.kivy-ios
’s dependencies, runpip install -r requirements.txt
. Then run:A few seconds or minutes later, you will get an error. If your build takes a very long time and succeeds (you don’t get an error), awesome! Skip the rest of this section and continue to Section 2.
So run:
requests
where the other imports are located.Recipe.download_file
method, replacewith
Make sure you indent with spaces. Then run:
After a long time, this command should finish successfully.
Section 2
Now run:
You can see the libraries that you can
./toolchain.py build
. For each package that your app requires: If the package was listed when you ran./toolchain.py recipes
, run:NOTE: Your app will require
python3
.If it wasn’t, run:
Section 3
Now you are almost ready. Run:
In Finder, right click on your <PROJECT_NAME_WITH_NO_SPECIAL_CHARS>-ios folder and click “Get Info.” Now click the lock on the bottom right corner of the window and type in your password. Under “Sharing & Permissions,” change all permissions to “Read & Write.” Click the settings icon in the bottom left of the window and click “Apply to enclosed items…” Click “OK” to apply the changes. Move one folder up and right click on the
kivy-ios
folder that you got from GitHub. Click “Get Info.” Click the lock on the bottom right corner of the window and type in your password. Under “Sharing & Permissions,” change all permissions to “Read & Write.” Click the settings icon in the bottom left of the window and click “Apply to enclosed items…” Click “OK” to apply the changes. Now in your terminal, run:Now, you probably know what to do in Xcode. I hope this comment helps you!
If you are having issues with Xcode, watch this.