I downloaded kivy successfully.
When I was trying to start the kivy window with this command that I found at the original kivy basics web site:
import kivy
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()
It gives an error:
ArgumentError Traceback (most recent call last)
D:\Anaconda\lib\site-packages\kivy\core\window\window_sdl2.py in mainloop(self)
746 try:
--> 747 self._mainloop()
748 except BaseException as inst:
D:\Anaconda\lib\site-packages\kivy\core\window\window_sdl2.py in _mainloop(self)
478 def _mainloop(self):
--> 479 EventLoop.idle()
480
D:\Anaconda\lib\site-packages\kivy\base.py in idle(self)
361 Logger.error('Base: Application will leave')
--> 362 self.exit()
363 return False
D:\Anaconda\lib\site-packages\kivy\base.py in exit(self)
374 '''Close the main loop and close the window.'''
--> 375 self.close()
376 if self.window:
D:\Anaconda\lib\site-packages\kivy\base.py in close(self)
171 self.quit = True
--> 172 self.stop()
173 self.status = 'closed'
D:\Anaconda\lib\site-packages\kivy\base.py in stop(self)
183 for provider in reversed(self.input_providers[:]):
--> 184 provider.stop()
185 if provider in self.input_providers_autoremove:
D:\Anaconda\lib\site-packages\kivy\input\providers\wm_pen.py in stop(self)
110 self.pen = None
--> 111 SetWindowLong_WndProc_wrapper(self.hwnd, self.old_windProc)
112
D:\Anaconda\lib\site-packages\kivy\input\providers\wm_common.py in _closure(hWnd, wndProc)
121 def _closure(hWnd, wndProc):
--> 122 oldAddr = func(hWnd, GWL_WNDPROC, cast(wndProc, c_void_p).value)
123 return cast(c_void_p(oldAddr), WNDPROC)
ArgumentError: argument 3: <class 'TypeError'>: wrong type
During handling of the above exception, another exception occurred:
ArgumentError Traceback (most recent call last)
D:\Anaconda\lib\site-packages\kivy\base.py in runTouchApp(widget, slave)
503 else:
--> 504 EventLoop.window.mainloop()
505 finally:
D:\Anaconda\lib\site-packages\kivy\core\window\window_sdl2.py in mainloop(self)
751
Please help me why doesn't it works?
Here is the example of working: https://kivy.org/doc/stable/guide/basic.html
Related
I get a keyerror upon calling the TRPO agent.learn() even though the key is defined in the observation below. Can anyone point out what might the reason for this?
self.observation_space = gym.spaces.Dict(
{'topo': gym.spaces.Discrete(10),
'the_service': gym.spaces.Discrete(10)}
)
The following agent line gives the error.
a = agent.learn(total_timesteps=1000, callback=callback)
The traceback is below.
KeyError Traceback (most recent call last)
Input In [14], in <cell line: 1>()
----> 1 a = agent.learn(total_timesteps=1000, callback=callback)
File ~\anaconda3\lib\site-packages\sb3_contrib\trpo\trpo.py:411, in TRPO.learn(self, total_timesteps, callback, log_interval, eval_env, eval_freq, n_eval_episodes, tb_log_name, eval_log_path, reset_num_timesteps)
398 def learn(
399 self,
400 total_timesteps: int,
(...)
408 reset_num_timesteps: bool = True,
409 ) -> OnPolicyAlgorithm:
--> 411 return super(TRPO, self).learn(
412 total_timesteps=total_timesteps,
413 callback=callback,
414 log_interval=log_interval,
415 eval_env=eval_env,
416 eval_freq=eval_freq,
417 n_eval_episodes=n_eval_episodes,
418 tb_log_name=tb_log_name,
419 eval_log_path=eval_log_path,
420 reset_num_timesteps=reset_num_timesteps,
421 )
File ~\anaconda3\lib\site-packages\stable_baselines3\common\on_policy_algorithm.py:242, in OnPolicyAlgorithm.learn(self, total_timesteps, callback, log_interval, eval_env, eval_freq, n_eval_episodes, tb_log_name, eval_log_path, reset_num_timesteps)
228 def learn(
229 self,
230 total_timesteps: int,
(...)
238 reset_num_timesteps: bool = True,
239 ) -> "OnPolicyAlgorithm":
240 iteration = 0
--> 242 total_timesteps, callback = self._setup_learn(
243 total_timesteps, eval_env, callback, eval_freq, n_eval_episodes, eval_log_path, reset_num_timesteps, tb_log_name
244 )
246 callback.on_training_start(locals(), globals())
248 while self.num_timesteps < total_timesteps:
File ~\anaconda3\lib\site-packages\stable_baselines3\common\base_class.py:429, in BaseAlgorithm._setup_learn(self, total_timesteps, eval_env, callback, eval_freq, n_eval_episodes, log_path, reset_num_timesteps, tb_log_name)
427 # Avoid resetting the environment when calling ``.learn()`` consecutive times
428 if reset_num_timesteps or self._last_obs is None:
--> 429 self._last_obs = self.env.reset() # pytype: disable=annotation-type-mismatch
430 self._last_episode_starts = np.ones((self.env.num_envs,), dtype=bool)
431 # Retrieve unnormalized observation for saving into the buffer
File ~\anaconda3\lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py:62, in DummyVecEnv.reset(self)
60 for env_idx in range(self.num_envs):
61 obs = self.envs[env_idx].reset()
---> 62 self._save_obs(env_idx, obs)
63 return self._obs_from_buf()
File ~\anaconda3\lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py:94, in DummyVecEnv._save_obs(self, env_idx, obs)
92 self.buf_obs[key][env_idx] = obs
93 else:
---> 94 self.buf_obs[key][env_idx] = obs[key]
KeyError: 'the_service'
Extra info: The observation_space is inside a class that the main entry point class inherits. i.e. main entry point class A inherits class B and it is in B the observation_space is defined as shown at the top.
I use a jupyter notebook and run twint.
Code
c = twint.Config()
c.Username = 'twitter'
c.Limit = 20
twint.run.Followers(c)
The above commands produce a runtime error relating to (I believe) the code attempting to create 2 asynchronous event loops.
Traceback as follows:
RuntimeError Traceback (most recent call last)
<ipython-input-4-4713cc05fb59> in <module>()
----> 1 twint.run.Favorites(c)
~/coding/tools/twint/twint/run.py in Favorites(config)
119 def Favorites(config):
120 config.Favorites = True
--> 121 run(config)
122
123 def Followers(config):
~/coding/tools/twint/twint/run.py in run(config)
115
116 def run(config):
--> 117 get_event_loop().run_until_complete(Twint(config).main())
118
119 def Favorites(config):
~/.pyenv/versions/3.6.5/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
453 future.add_done_callback(_run_until_complete_cb)
454 try:
--> 455 self.run_forever()
456 except:
457 if new_task and future.done() and not future.cancelled():
~/.pyenv/versions/3.6.5/lib/python3.6/asyncio/base_events.py in run_forever(self)
407 self._check_closed()
408 if self.is_running():
--> 409 raise RuntimeError('This event loop is already running')
410 if events._get_running_loop() is not None:
411 raise RuntimeError(
RuntimeError: This event loop is already running
I have found a solution for Jupyter notebooks
using the nest_async
Simply do
pip install nest_asyncio
And add these lines.
import nest_asyncio
nest_asyncio.apply()
I am trying to load a sasbdat file in python using pd.read_sas() and I fail to load the data due to the below error.
ValueError Traceback (most recent call last)
<ipython-input-148-64f915da8256> in <module>
----> 1 df_sas = pd.read_sas('input_sasfile.sas7bdat', format='sas7bdat')
~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sasreader.py in read_sas(filepath_or_buffer, format, index, encoding, chunksize, iterator)
121
122 reader = SAS7BDATReader(
--> 123 filepath_or_buffer, index=index, encoding=encoding, chunksize=chunksize
124 )
125 else:
~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in __init__(self, path_or_buf, index, convert_dates, blank_missing, chunksize, encoding, convert_text, convert_header_text)
144
145 self._get_properties()
--> 146 self._parse_metadata()
147
148 def column_data_lengths(self):
~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in _parse_metadata(self)
349 self.close()
350 raise ValueError("Failed to read a meta data page from the SAS file.")
--> 351 done = self._process_page_meta()
352
353 def _process_page_meta(self):
~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in _process_page_meta(self)
355 pt = [const.page_meta_type, const.page_amd_type] + const.page_mix_types
356 if self._current_page_type in pt:
--> 357 self._process_page_metadata()
358 is_data_page = self._current_page_type & const.page_data_type
359 is_mix_page = self._current_page_type in const.page_mix_types
~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in _process_page_metadata(self)
388 subheader_signature = self._read_subheader_signature(pointer.offset)
389 subheader_index = self._get_subheader_index(
--> 390 subheader_signature, pointer.compression, pointer.ptype
391 )
392 self._process_subheader(subheader_index, pointer)
~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in _get_subheader_index(self, signature, compression, ptype)
401 else:
402 self.close()
--> 403 raise ValueError("Unknown subheader signature")
404 return index
405
ValueError: Unknown subheader signature
Though I found relevant github issue (https://github.com/pandas-dev/pandas/issues/24794), but it was closed because the issue got resolved by updating the pandas.
Any help is greatly appreciated.
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.config import Config
from kivy.uix.button import Button
from kivy.uix.filechooser import FileChooserListView
Config.set('graphics', 'fullscreen', '0')#keeps screen in a smaller window when running
Config.write()
import os
class MyWidget(BoxLayout):
def __init__(self, **kwargs):
super(MyWidget,self).__init__(**kwargs)
container = BoxLayout(orientation='vertical')
filechooser = FileChooserListView()
filechooser.bind(on_selection=lambda x: self.selected(filechooser.selection))
open_btn = Button(text='open', size_hint=(1, .2))
open_btn.bind(on_release=lambda x: self.open(filechooser.path, filechooser.selection))
container.add_widget(filechooser)
container.add_widget(open_btn)
self.add_widget(container)
def open(self, path, filename):
print(filename)
if len(filename) > 0:
with open(os.path.join(path, filename[0])) as f:
print(f.read())
def selected(self, filename):
print("selected: %s" % filename[0])
class MyApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
MyApp().run()
I am trying to create a program that can open files in kivy, I have a feeling its something to do with my 'os.path.join' I tried to add 'enconding =utf-8' to the area in the code where it says 'with open' that did not work in both cases. Below is the full error, maybe im missing something but hopefully the full error will help.
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-1-ad2b3c0779e3> in <module>
45
46 if __name__ == '__main__':
---> 47 MyApp().run()
~\anaconda3\lib\site-packages\kivy\app.py in run(self)
853
854 self.dispatch('on_start')
--> 855 runTouchApp()
856 self.stop()
857
~\anaconda3\lib\site-packages\kivy\base.py in runTouchApp(widget, slave)
502 _run_mainloop()
503 else:
--> 504 EventLoop.window.mainloop()
505 finally:
506 stopTouchApp()
~\anaconda3\lib\site-packages\kivy\core\window\window_sdl2.py in mainloop(self)
745 while not EventLoop.quit and EventLoop.status == 'started':
746 try:
--> 747 self._mainloop()
748 except BaseException as inst:
749 # use exception manager first
~\anaconda3\lib\site-packages\kivy\core\window\window_sdl2.py in _mainloop(self)
477
478 def _mainloop(self):
--> 479 EventLoop.idle()
480
481 # for android/iOS, we don't want to have any event nor executing our
~\anaconda3\lib\site-packages\kivy\base.py in idle(self)
340
341 # read and dispatch input from providers
--> 342 self.dispatch_input()
343
344 # flush all the canvas operation
~\anaconda3\lib\site-packages\kivy\base.py in dispatch_input(self)
325 post_dispatch_input = self.post_dispatch_input
326 while input_events:
--> 327 post_dispatch_input(*pop(0))
328
329 def idle(self):
~\anaconda3\lib\site-packages\kivy\base.py in post_dispatch_input(self, etype, me)
291 wid.dispatch('on_touch_up', me)
292 else:
--> 293 wid.dispatch('on_touch_up', me)
294
295 wid._context.pop()
kivy\_event.pyx in kivy._event.EventDispatcher.dispatch()
~\anaconda3\lib\site-packages\kivy\uix\behaviors\button.py in on_touch_up(self, touch)
177 else:
178 self._do_release()
--> 179 self.dispatch('on_release')
180 return True
181
kivy\_event.pyx in kivy._event.EventDispatcher.dispatch()
kivy\_event.pyx in kivy._event.EventObservers.dispatch()
kivy\_event.pyx in kivy._event.EventObservers._dispatch()
<ipython-input-1-ad2b3c0779e3> in <lambda>(x)
23
24 open_btn = Button(text='open', size_hint=(1, .2))
---> 25 open_btn.bind(on_release=lambda x: self.open(filechooser.path, filechooser.selection))
26
27 container.add_widget(filechooser)
<ipython-input-1-ad2b3c0779e3> in open(self, path, filename)
33 if len(filename) > 0:
34 with open(os.path.join(path, filename[0])) as f:
---> 35 print(f.read())
36
37 def selected(self, filename):
~\anaconda3\lib\encodings\cp1252.py in decode(self, input, final)
21 class IncrementalDecoder(codecs.IncrementalDecoder):
22 def decode(self, input, final=False):
---> 23 return codecs.charmap_decode(input,self.errors,decoding_table)[0]
24
25 class StreamWriter(Codec,codecs.StreamWriter):
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 57: character maps to <undefined>
I am very new to establishing GUI's and Kivy, I am using Python 3. I have tried to run a basic code which I have found online but there seems to be an encoding issue which I couldn't solve. My code goes as:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text = "A")
if __name__ == "__main__":
MyApp().run()
The error message I get is this:
UnicodeEncodeError: 'charmap' codec can't encode character '\u0131' in position 280: character maps to undefined
Complete Traceback:
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-3-2a8b8f5ea334> in <module>
12
13
---> 14 MyApp().run()
C:\ProgramData\Anaconda3\lib\site-packages\kivy\app.py in run(self)
827 self.load_config()
828 self.load_kv(filename=self.kv_file)
--> 829 root = self.build()
830 if root:
831 self.root = root
<ipython-input-3-2a8b8f5ea334> in build(self)
9
10 def build(self):
---> 11 return Label(text='Hello world')
12
13
kivy\_event.pyx in kivy._event.EventDispatcher.__cinit__()
kivy\properties.pyx in kivy.properties.Property.link()
kivy\properties.pyx in kivy.properties.NumericProperty.init_storage()
kivy\properties.pyx in kivy.properties.Property.init_storage()
kivy\properties.pyx in kivy.properties.NumericProperty.convert()
kivy\properties.pyx in kivy.properties.NumericProperty.parse_str()
kivy\properties.pyx in kivy.properties.NumericProperty.parse_list()
kivy\properties.pyx in kivy.properties.dpi2px()
C:\ProgramData\Anaconda3\lib\site-packages\kivy\utils.py in __get__(self, inst, cls)
503 if inst is None:
504 return self
--> 505 retval = self.func(inst)
506 setattr(inst, self.func.__name__, retval)
507 return retval
C:\ProgramData\Anaconda3\lib\site-packages\kivy\metrics.py in dpi(self)
172 # for all other platforms..
173 from kivy.base import EventLoop
--> 174 EventLoop.ensure_window()
175 return EventLoop.window.dpi
176
C:\ProgramData\Anaconda3\lib\site-packages\kivy\base.py in ensure_window(self)
121 '''Ensure that we have a window.
122 '''
--> 123 import kivy.core.window # NOQA
124 if not self.window:
125 Logger.critical('App: Unable to get a Window, abort.')
C:\ProgramData\Anaconda3\lib\site-packages\kivy\core\window\__init__.py in <module>
2066 if platform == 'linux':
2067 window_impl += [('x11', 'window_x11', 'WindowX11')]
-> 2068 Window = core_select_lib('window', window_impl, True)
C:\ProgramData\Anaconda3\lib\site-packages\kivy\core\__init__.py in core_select_lib(category, llist, create_instance, base, basemodule)
101 'debug logging (e.g. add -d if running from the command line, or '
102 'change the log level in the config) and re-run your app to '
--> 103 'identify potential causes\n{1}'.format(category.capitalize(), err))
104
105
C:\ProgramData\Anaconda3\lib\logging\__init__.py in critical(self, msg, *args, **kwargs)
1428 """
1429 if self.isEnabledFor(CRITICAL):
-> 1430 self._log(CRITICAL, msg, args, **kwargs)
1431
1432 fatal = critical
C:\ProgramData\Anaconda3\lib\logging\__init__.py in _log(self, level, msg, args, exc_info, extra, stack_info)
1517 record = self.makeRecord(self.name, level, fn, lno, msg, args,
1518 exc_info, func, extra, sinfo)
-> 1519 self.handle(record)
1520
1521 def handle(self, record):
C:\ProgramData\Anaconda3\lib\logging\__init__.py in handle(self, record)
1527 """
1528 if (not self.disabled) and self.filter(record):
-> 1529 self.callHandlers(record)
1530
1531 def addHandler(self, hdlr):
C:\ProgramData\Anaconda3\lib\logging\__init__.py in callHandlers(self, record)
1589 found = found + 1
1590 if record.levelno >= hdlr.level:
-> 1591 hdlr.handle(record)
1592 if not c.propagate:
1593 c = None #break out
C:\ProgramData\Anaconda3\lib\logging\__init__.py in handle(self, record)
903 self.acquire()
904 try:
--> 905 self.emit(record)
906 finally:
907 self.release()
C:\ProgramData\Anaconda3\lib\site-packages\kivy\logger.py in emit(self, message)
245 self._write_message(_message)
246
--> 247 self._write_message(message)
248
249
C:\ProgramData\Anaconda3\lib\site-packages\kivy\logger.py in _write_message(self, record)
216 stream.write(fs % msg.encode("UTF-8"))
217 else:
--> 218 stream.write(fs % msg)
219 stream.flush()
220
C:\ProgramData\Anaconda3\lib\encodings\cp1252.py in encode(self, input, final)
17 class IncrementalEncoder(codecs.IncrementalEncoder):
18 def encode(self, input, final=False):
---> 19 return codecs.charmap_encode(input,self.errors,encoding_table)[0]
20
21 class IncrementalDecoder(codecs.IncrementalDecoder):
UnicodeEncodeError: 'charmap' codec can't encode character '\u0131' in position 280: character maps to <undefined>
```