Naraxus
Naraxus

Reputation: 101

Install Kivy on MacOS 12 (Monterey) with M1 Chip

After hours of trial an error, I hope, somebody can help me here.

I got my MacBook Air (M1, 2020) and want to use kivy for python-programming on it. When I first bought the Laptop 3 month ago it took a lot of work to find a way to run kivy/ execute my kivy-code on it. Finally, I ended up with the Kivy.app version which created [please excuse my limited understanding...] a Application, I could drag my python-files on or execute the files via the command line like kivy main.py. The "usual" way of simply installing kivy via pipdid never work (as far as I understood because the presented wheel is not compatible with the M1-Chip).

Now, I upgraded my MacOS to Monterey, which crashed everything. I can't even give a lot of information about what's broken. when I try to drag files on the Kivy-Application simply nothing happens. Executing any file (even a simple print("Hello")via the command line (like kivy main.py) results in

kivy
/Applications/Kivy.app/Contents/Resources/venv/bin /Applications/Kivy.app/Contents/Resources /Applications/Kivy.app/Contents/Resources
ImportError: No module named site

Since I don't use any special setup, just the fresh updated MacOS in it's newest version and python (installed via homebrew and already reinstalled after updating the OS) I hope anyone with more understanding of the how's and why's than me already fixed this problem for him/her self and can enlighten me.

Upvotes: 2

Views: 3411

Answers (2)

akarca
akarca

Reputation: 1516

I could run kivy on MacOS with M1 chip using rosetta 2.

  1. Install rosetta 2

    softwareupdate --install-rosetta

  2. Start a terminal with rosetta. Right click to /Applications/iTerm or /Applicatins/Utilities/Terminal > Get Info > Open Using Rosetta

  3. Create a fresh virtualenv. Install requirements

    pip install kivy[base] kivy-examples

  4. Run main.py (python main.py)

main.py

import kivy
kivy.require('2.0.0')

from kivy.app import App
from kivy.uix.label import Label

class MyApp(App):

    def build(self):
        return Label(text='Hello world')

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

Upvotes: 1

Luca
Luca

Reputation: 1

Do you have Rosetta2 installed? I ask because Kivy.app is an Intel Application and cannot work without that.

Install CLI Kivy Tools for Apple M1 Chip Mac

You need Homebrew and XCode, follow this guide:

After calling either:

python setup.py build_ext --inplace

...or your "make" command, you can call sudo make install to build Kivy in your Python3 folder and remove the folder you downloaded previously.

If, during the build, you have an error due to missing cython, you need to install cython from the source; you can do this here.

P.S., I don't know how kivy.app works, but I use VSCode + Kivy CLI 2.1.0dev and when I launch the kivy app (with imported module of kivy); it launches with kivy, but when I try to launch the print('hello') program, it only launches from the console (not with kivy).

Upvotes: 0

Related Questions