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.
I could run kivy on MacOS with M1 chip using rosetta 2.
Install rosetta 2
softwareupdate --install-rosetta
Start a terminal with rosetta. Right click to /Applications/iTerm or /Applicatins/Utilities/Terminal > Get Info > Open Using Rosetta
Create a fresh virtualenv. Install requirements
pip install kivy[base] kivy-examples
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()
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:
Dependencies (for macOS); you need one more dependency:
brew install ffmpeg
Install step; see "Development install".
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).
Related
I installed pygame through cmd using pip install pygame which can be seen in the ss. For some reason im unable to import it in my main.py file. Is there some way for me to fix this?(screenshot of terminal and vscode file)
I faced the same issue, but I had used the terminal. What I had done:
Deleted pygame which was installed via pip.
Installed it from the official website.
Then imported pygame. It fixed the issue.
I use linux
Alternatively, you can open the app installer of your device and search "pygame". Hopefully the module shows up.
I tried the code:
import kivy
from kivy.app import app
and it gives me the error 'no package called kivy'. I have installed kivy but its still giving me this error. Somebody said that kivy is not supported by python 3.8 so I decided to download 3.6 from python.org but something is wrong..when I click on the downloaded file, it just takes me to more files with several codes but nothing about installation. I am confused what do I do?
I have been building an application on Linux using python pygobject, and now I need to distribute it on Windows.
I first installed pygobject via msys2 (as per the official pygobject documentation)
Now, using msys2/mingw32, I can run my program typing
python3 main.py
But when I try to freeze it into a .exe with Pyinstaller, and try to run the produced .exe
If I Don't use --onefile, I get an import error on the _struct module (whereas "import _struct" works in python shell)
If I use --onefile, I get the Following error :
error:
lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-ani.dll could not be extracted!
fopen: No such file or directory
I’m using the devel version of Pyinstaller. I know next to nothing on Windows OS… does anyone know how to fix that error ?
It sounds like you were on the right path, unfortunately you ran in to a bug in PyInstaller. The good news is that the issue with the No module named '_struct' error is now fixed and released in version 3.6 and later. I would recommend using the --onedir mode of PyInstaller, you should be able to successfully package a GTK app for Windows.
So I'm trying to fix up an old program and I've been trying to run its main script on my Mac, but it says it can't find module gtk (it says it's a required dependency in the README). I have tried a ton of things to get this script to run, I've installed both python 2 and 3 with brew, installed many versions of pygtk with brew, tried to run the script on my user dir and in a python 2 and 3 virtualenv, added #!/usr/bin/env python2 and added a sys path to where brew installed pygtk, but all to no avail. Neither gtk nor pygtk can seem to be found. My original attempt at using pip to install pygtk resulted in this output:
Complete output from command python setup.py egg_info:
********************************************************************
* Building PyGTK using distutils is only supported on windows. *
* To build PyGTK in a supported way, read the INSTALL file. *
********************************************************************
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
/private/var/folders/6l/k1kfh5415ln0886zznkffpr80000gn/T/pip-install-
50TCjw/pygtk/
So... my question is: how should I proceed? I'm actually not sure what gtk does. Should I attempt to update this program to python3 compatibility? What is the state of compatibility for gtk? And how can I check if I actually even have gtk on my system? Because homebrew is pretty convinced that I do.
Update:
So I manually used the python2.7 that was installed via brew (in usr/local/Cellar/python#2) and this seemed to fix the gtk problem. However now it can't import webkit module which is somewhere else in the program, and I'm stuck here now...
Finally got all the dependancies loaded. python-webkit was apparently completely deprecated, I had to find the last macOS compatible version of it at https://code.google.com/archive/p/pywebkitgtk/downloads and then it was a simple matter of running its configure file and adding its install location to my Cellar python#2 program's sys path. Now the rest of the program is pretty messed up but I accomplished what I wanted for now
I just installed kivy on python 3.5.0. However, every time I try to import kivy; it shows the error "No module named Kivy".
I am very new to all this so step by step instructions would be helpful.
Many operating systems come with python 2.7 and 3.5 already installed. I know you said you have 3.5, but check this anyway with python2 -V. In the comments,you said that you have been importing kivy correctly into your files. It may be that you are accidentally running your python3 app with python2.
Kivy for python2 is not the same as kivy for python3. If you want to be sure that you're running with the python version you want, run your app with python3 filename.py.
If all this is said and done, and you still don't find out what's wrong, you either installed kivy for python2 somehow or it's searching for kivy in the wrong place.