简体   繁体   中英

How can I run Kivy on my Mac with M1 chip

MacOS: Monterey 12.0.1, currently (16-11-21) latest version

IDE: Visual Studio Code

I want to use Kivy to create some simple desktop app interfaces for a university project. I followed the instructions found on kivy.org:

  • pip install venv tools,
  • creating and activating the venv,
  • installing additional dependencies using brew,
  • python3 -m pip install kivy[base] kivy_examples ,
  • running a default 'Hello world!' file:
from kivy.uix.button import Button

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

TestApp().run()

This is the output it gives me:

(kivy_venv) jdhamelink@Josefs-MacBook-Air UNO_X % /Users/jdhamelink/Local/UNO_X/kivy_venv/bin/python /Users/jdhamelink/Local/UNO_X/main.py
[INFO   ] [Logger      ] Record log in /Users/jdhamelink/.kivy/logs/kivy_21-11-16_6.txt
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "/Users/jdhamelink/Local/UNO_X/kivy_venv/lib/python3.8/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.8.9 (default, Aug  3 2021, 19:21:54) 
[Clang 13.0.0 (clang-1300.0.29.3)]
[INFO   ] [Python      ] Interpreter at "/Users/jdhamelink/Local/UNO_X/kivy_venv/bin/python"
[ERROR  ] [Clock       ] Unable to import kivy._clock. Have you perhaps forgotten to compile kivy? Kivy contains Cython code which needs to be compiled. A missing kivy._clock often indicates the Cython code has not been compiled. Please follow the installation instructions and make sure to compile Kivy
 Traceback (most recent call last):
   File "/Users/jdhamelink/Local/UNO_X/main.py", line 1, in <module>
     from kivy.app import App
   File "/Users/jdhamelink/Local/UNO_X/kivy_venv/lib/python3.8/site-packages/kivy/app.py", line 411, in <module>
     from kivy.base import runTouchApp, async_runTouchApp, stopTouchApp
   File "/Users/jdhamelink/Local/UNO_X/kivy_venv/lib/python3.8/site-packages/kivy/base.py", line 28, in <module>
     from kivy.clock import Clock
   File "/Users/jdhamelink/Local/UNO_X/kivy_venv/lib/python3.8/site-packages/kivy/clock.py", line 466, in <module>
     from kivy._clock import CyClockBase, ClockEvent, FreeClockEvent, \
 ImportError: dlopen(/Users/jdhamelink/Local/UNO_X/kivy_venv/lib/python3.8/site-packages/kivy/_clock.cpython-38-darwin.so, 0x0002): tried: '/Users/jdhamelink/Local/UNO_X/kivy_venv/lib/python3.8/site-packages/kivy/_clock.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_clock.cpython-38-darwin.so' (no such file), '/usr/lib/_clock.cpython-38-darwin.so' (no such file)

I think it might have something to do with the architecture, because of the Importerror on last line, specifically:

tried: '/Users/jdhamelink/Local/UNO_X/kivy_venv/lib/python3.8/site-packages/kivy/_clock.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_clock.cpython-38-darwin.so' (no such file), '/usr/lib/_clock.cpython-38-darwin.so' (no such file)

Online I couldn't find a clear solution to this problem, but my suspicion is that it might have something to do with the "new" M1 chips which might have an architecture that gives rise to some problems. It could very well be the case that I forgot some very obvious step during the installation, as I'm also getting a hint that I might have forgotten to compile the Cython code, something that I've never heard of before. Can someone help me?

--- EDIT ---

I have kivy installed on the virtual environment as well as "globally" using pip3

pip3 install git+https://github.com/kivy/kivy.git

try using this command in the terminal, it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM