question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleNotFoundError: no module name kivy

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
Python3-8commented, Jun 5, 2022

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

$ cd ~ # Or any directory
$ git clone git://github.com/kivy/kivy-ios
$ cd kivy-ios
$ nano toolchain.py
  • Add #! /usr/bin/env python3 to the beginning of the file.
  • Now is a good time to create a virtual environment by running virtualenv venv if you want to. You might need to run pip install virtualenv to install the virtualenv tool.
  • To install kivy-ios’s dependencies, run pip install -r requirements.txt. Then run:
$ chmod +x toolchain.py
$ ./toolchain.py build kivy

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:

$ nano kivy_ios/toolchain.py
  • Import requests where the other imports are located.
  • In the Recipe.download_file method, replace
try:
    urlretrieve(url, filename, report_hook)
except OSError:
...

with

try:
    with open(filename, 'wb') as filename_:
        filename_.write(requests.get(url).content)
except:
...

Make sure you indent with spaces. Then run:

$ ./toolchain.py build kivy

After a long time, this command should finish successfully.

Section 2

Now run:

$ ./toolchain.py recipes

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:

$ ./toolchain.py build <PACKAGE>

NOTE: Your app will require python3.

If it wasn’t, run:

$ ./toolchain.py pip install <LIBRARY>

Section 3

Now you are almost ready. Run:

$ ./toolchain.py create <PROJECT_NAME_WITH_NO_SPECIAL_CHARS> <CODE_DIR> # Note: There should be a main.py in your code directory
$ open .

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:

$ open <PROJECT_NAME_WITH_NO_SPECIAL_CHARS>-ios/<PROJECT_NAME_WITH_NO_SPECIAL_CHARS>.xcodeproj/

Now, you probably know what to do in Xcode. I hope this comment helps you!

1reaction
Python3-8commented, Aug 21, 2020

If you are having issues with Xcode, watch this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named kivy.app - python 2.7 - Stack Overflow
I ran into this error message when I named the script kivy.py , because python looks first in the current directory to fill...
Read more >
No module named 'kivy' - AFTER I successfully installed Kivy...?
In windows make sure to have installed latest version of Python (3.7+), and then install kivy using pip. On Linux, remove Python2(if it...
Read more >
No module named 'kivy'' in Python 3 - Quora
ModuleNotFoundError in python implies that you have not installed the package and hence, python is unable to import it. Install pip package installer...
Read more >
No module named 'kivy' · Issue #7218 - GitHub
The issue you're having is unrelated to the python version. You seem to have installed kivy in conda, but then try to run...
Read more >
Python Import Error Module Not Found Error - YouTube
Python Import Error Module Not Found Error : No Module Named Kivy In Ubuntu LinuxTo Install Kivy in Ubuntu Linux: sudo apt install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found