I am attempting to run a basic hello world app for a Python GUI library called kivy--which the developers provide here --in the new Bash on Ubuntu on Windows environment. I've saved the example code as main.py
as shown below:
import kivy
kivy.require('1.9.1') # my current kivy version
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()
When I attempt to run this simple app using python main.py
(or even sudo python main.py
if something was needing permissions) I get the following error:
[INFO ][Logger ] Record log in /home/jdaymude/.kivy/logs/kivy_16-08-17_3.txt
[INFO ][Kivy ] v1.9.1
[INFO ][Python ] v2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2]
Traceback (most recent call last):
File "main.py", line 5, in <module>
from kivy.app import App
File "/usr/local/lib/python2.7/dist-packages/kivy/app.py", line 319, in <module>
from kivy.base import runTouchApp, stopTouchApp
File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 29, in <module>
from kivy.clock import Clock
File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 709, in <module>
Clock = register_context('Clock', ClockBase)
File "/usr/local/lib/python2.7/dist-packages/kivy/context.py", line 83, in register_context
instance = cls(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 436, in __init__
self._start_tick = self._last_tick = self.time()
File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 273, in _time
raise OSError(_errno, strerror(_ernno))
OSError: [Errno 22] Invalid argument
I haven't found any other StackOverflow questions with a similar error, and going through the kivy issue tracker didn't indicate any related issues with the software. To me, this indicates that I'm doing something wrong, so any suggestions would be most helpful. My Ubuntu version is 14.04, I've updated python
, python3
, kivy
, and all of their dependencies, and have installed/successfully tested an Xterm program to launch the GUI when the kivy app does work.
After some discussion in the comments, I'm including details on installation for further clarification. I followed the instructions the kivy developers provided for Installation on Linux , which boils down to the following:
sudo add-apt-repository ppa:kivy-team/kivy
sudo apt-get update
sudo apt-get install python-kivy python3-kivy
Since I'm new to kivy and wanted to cover all my bases, I also installed a handful of what the install guide calls "common dependencies" using sudo apt-get install
, including: python-dev
, python3-dev
, python-pip
, and all the others shown at the linked page for SDL2
and pygame
. Although not relevant to my efforts since I wanted a global install, I also followed their instructions for using virtualenv
and that also gave the same error.
I don't know if a solution was already posted somewhere. A quick Google search didn't show up anything. A hack I found was patching lib/python2.7/site-packages/kivy/clock.py
file (in your virtualenv). In def _get_sleep_obj():
function definition, force the code to go to if True or platform in ('win32', 'cygwin'):
path.
With this change, the "Hello Word" and other example apps started working.
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.