Python throws exception on import using pgu with pygame - python

When I from pgu import pgu as pgui I get the following exception:
Traceback (most recent call last):
File "C:/path/pyspace/main.py", line 3, in <module>
from simulator.game import Game
File "C:\path\pyspace\simulator\game.py", line 5, in <module>
from simulator.guis.simulategui import SimulateGUI
File "C:\path\pyspace\simulator\guis\__init__.py", line 2, in <module>
from simulator.guis.simulategui import SimulateGUI
File "C:\path\pyspace\simulator\guis\simulategui.py", line 5, in <module>
from pgu import gui as pgui
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pgu\gui\__init__.py", line 21, in <module>
from .container import Container
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pgu\gui\container.py", line 57
except StyleError,e:
when I open the ...\gui\container.py with pycharm there is an error that tells me that Python version 3.5 does not support this syntax. The syntax in container.py in pgu is as follows:
try:
# This hack isn't perfect and so it's not enabled by default, but only by
# themes that explicitly request it.
alpha = pguglobals.app.theme.getstyle("pgu", "", "themealpha")
except StyleError,e:
alpha = False
I am running python 3.5.1 with pygame 1.9.2a0 and pgu 0.18. Do I need to install a different version of pgu or different version of a GUI manager for pygame altogether, or is there a simple way to solve this? I'm assuming I get to install a different GUI manager; but was hoping that there is a simple fix to this.

It looks like pgu is still using Python 2.7 exception handling. You could change your local copy to read
except StyleError as e:
but that would still have to be sent upstream if you're redistributing the code.

Related

Trying to get Python Arcade to work on Ubuntu

I have installed Python Arcade using
pip install arcade
which ran successfully.
When trying to run the example code, or even just trying to import arcade from the Python command line, I receive an error
>>> import arcade
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/brian/.local/lib/python3.8/site-packages/arcade/__init__.py", line 250, in <module>
from .joysticks import get_game_controllers
File "/home/brian/.local/lib/python3.8/site-packages/arcade/joysticks.py", line 1, in <module>
import pyglet.input
File "/home/brian/.local/lib/python3.8/site-packages/pyglet/input/__init__.py", line 179, in <module>
from .evdev import get_devices as evdev_get_devices
File "/home/brian/.local/lib/python3.8/site-packages/pyglet/input/evdev.py", line 509, in <module>
class EvdevControllerManager(ControllerManager, XlibSelectDevice):
File "/home/brian/.local/lib/python3.8/site-packages/pyglet/input/evdev.py", line 583, in EvdevControllerManager
def get_controllers(self) -> list[Controller]:
TypeError: 'type' object is not subscriptable
>>>
Python version is 3.8.10, and OS is Ubuntu 20.04, but I can't get past this error.
This is a known bug in the pyglet library: https://github.com/pyglet/pyglet/issues/614
The code uses list[Controller] which requires Python 3.9 (see PEP 585).
The line was introduced to pyglet in commit 3c2c7de and was fixed in commit 63341c4 (10 days ago as of today), which changes it to List[Controller] (where List is imported from the standard typing module).
Based on the response from #mkrieger1, and the error being shown, I took the following steps:
vim /home/brian/.local/lib/python3.8/site-packages/pyglet/input/evdev.py
added a line below the other import sections at the top
import typing
then went to line 583 (now 584 due to adding above), and changed
def get_controllers(self) -> list[Controller]:
to
def get_controllers(self) -> typing.List[Controller]:
and the example programs are now working.
If anyone else is in the same situation, then hopefully this is a quick fix to try.

Python can't load libc when importing xfsm module

I'm trying to write Python code to manipulate Xerox FST files, and I've installed the Python bindings for libxfsm and the XFSM library available through http://fsmbook.com. I'm running 64-bit Ubuntu. The installation goes fine, but when I try to import the xfsm module, I get this error:
>>> import xfsm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/xfsm/__init__.py", line
30, in <module>
import xfsm.errors # So error handler gets installed
File "/usr/local/lib/python2.7/dist-packages/xfsm/errors.py", line
8, in <module>
from xfsm.utils import *
File "/usr/local/lib/python2.7/dist-packages/xfsm/utils.py", line
39, in <module>
libc = cfsm.load_library("c")
File "/usr/local/lib/python2.7/dist-packages/xfsm/cfsm_api.py", line
366, in l oad_library
raise ImportError("%s not found." % libname)
ImportError: c not found.
Inspecting the source code for the Python interface, it looks like it is trying and failing to find libc, and failing, but I am at a loss on how to fix that.
Has anybody else gotten the Python-XFST interface working, or have any idea what's going wrong and how to fix it?
I had same problem on 64-bit Ubuntu 14.04. The problem is it can't find libc. In my case libc on my OS is name libc.so.6(I don't know why, I am new on Ubuntu). But the Python-XFST doesn't recognize it (Detail your can refer to source file)
My solution is simple, just modify xfsm/utils.py file in
**Line 39** : libc = cfsm.load_library("c")
to
**Line 39** : libc = cfsm.load_library("libc.so.6")
Remember to add the path to libc.so.6 in env.

Python error: No module named RuntimeError

Im trying to figured out this problem. Yesterday I installed PyScripter and since then, scripts doesnt work. When I run any script (in PyScripter or IDLE) and trying to "import arcpy", it gets this error:
import arcpy
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 14, in <module>
import arcgisscripting
File "C:\Python26\ArcGIS10.0\lib\arcgisscripting.py", line 81, in <module>
from RuntimeError import RuntimeError
ImportError: No module named RuntimeError
Have somebody any suggestion how to fix it?
Thanks to all very much!
Sounds like the module is not installed properly (or at all). To verify, do the following:
open a shell and start the python shell by typing python
(If this doesn't display an error, check that python is added to your system path or if it is even installed at all. But if you've used Python on said machine maybe system path issue)
enter the commmand help('modules')
review the list of modules that's returned to see whether arcpy is included
if not, then you may have to reinstall the module

python pyglet and opengl

I am trying to get 3D capabilities through python and have download pyglet. While going through the first example in this tutorial I got a bunch of strange errors that I cannot discern. The following is the script I am trying to run:
import pyglet
win = pyglet.window.Window()
#win.event
def on_draw():
win.clear()
pyglet.app.run()
2 The following is the output I received from the python interpreter after I imported my script:
>>> import test as t
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.py", line 13, in <module>
pyglet.app.run()
File "/usr/lib/pymodules/python2.7/pyglet/app/__init__.py", line 264, in run
EventLoop().run()
File "/usr/lib/pymodules/python2.7/pyglet/app/xlib.py", line 93, in run
sleep_time = self.idle()
Fihttp://greendalecs.wordpress.com/2012/04/21/3d-programming-in-python-part-1/#commentsle "/usr/lib/pymodules/python2.7/pyglet/app/__init__.py", line 193, in idle
window.dispatch_event('on_draw')
File "/usr/lib/pymodules/python2.7/pyglet/window/__init__.py", line 1219, in dispatch_event
EventDispatcher.dispatch_event(self, *args)
File "/usr/lib/pymodules/python2.7/pyglet/event.py", line 340, in dispatch_event
if handler(*args):
File "test.py", line 13, in on_draw
pyglet.app.run()
NameError: global name 'GL_COlOR_BUFFER_BIT' is not defined
How can I fix these errors? I use Ubuntu 12.04 LTS and Emacs 24.3.
I have downloaded pyglet, through apt-get install but is there anything else I needed to do? Perhaps I do not have drivers configured or I need different software.
If you need more information let me know!
GL_COlOR_BUFFER_BIT is undefined, because the value you are looking for is called GL_COLOR_BUFFER_BIT...
For future reference, as of Pyglet 1.1.4, this is because 1.1.4 no longer supports "recent" versions of Mac OS.
However, the most recent non-released version of Pyglet DOES support, with a full new interface using Cocoa. So, until Pyglet 1.2 is released, you have to install Pyglet directly from the trunk, using e.g.
pip install --upgrade http://pyglet.googlecode.com/archive/tip.zip

have trouble with PIL to create PhotoImage object

I have Python 2.6 running on Fedora 13. I installed PIL 1.1.7, and I get the successful installed message in the Python prompt. I am able to import PIL.PhotoImage,but when I try to run the following, I get an error.
mgobj = PhotoImage(file=imgpath)
Stacktrace:
Traceback (most recent call last):
File "viewer-tk.py", line 25, in <module>
imgobj = PhotoImage(file=imgpath) # now JPEGs work!
File "/home/Toshiba/vinpython/venv/lib/python2.6/site-packages/PIL/ImageTk.py", line 116, in __init__
self.paste(image)
File "/home/Toshiba/vinpython/venv/lib/python2.6/site-packages/PIL/ImageTk.py", line 181, in paste
import _imagingtk
ImportError: No module named _imagingtk
In the module ImageTk.py , I see _imagingtk being imported,but i am not sure how do it get that module.Help is greatly appreciated!!!
You need to install Tkinter python module as stated at this trac. But since it's an integral part of python distributions. Since you are using fedora take a look at this page where you can install Tkinter when it doesn't come along, even being for Fedora 3 I think it might help.

Categories