python pyglet and opengl - python

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

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.

Mouse, and keyboard python modules conflicting?

I am writing a test program which contains the mouse, and keyboard modules together, but they conflict when I run the program.
If applicable, I run Linux Mint 20.04 (Uma).
Here is my code:
import keyboard
import mouse
import time
time.sleep(2)
print("Finished part 1!")
x, y = mouse.get_position()
time.sleep(2)
print("Finished part 2!")
mouse.move(x, y)
time.sleep(2)
print("Finished part 3!")
keyboard.add_hotkey('ctrl+alt+c', mouse.move(x, y))
If I run this program normally, such as /bin/python3 /home/bhrz/Scripts/Python/Mouse/main.py in my terminal, it outputs:
Finished part 1!
Finished part 2!
Finished part 3!
Traceback (most recent call last):
File "/home/bhrz/Scripts/Python/Mouse/main.py", line 18, in <module>
keyboard.add_hotkey('ctrl+alt+c', mouse.move(x, y))
File "/usr/local/lib/python3.8/dist-packages/keyboard/__init__.py", line 639, in add_hotkey
_listener.start_if_necessary()
File "/usr/local/lib/python3.8/dist-packages/keyboard/_generic.py", line 35, in start_if_necessary
self.init()
File "/usr/local/lib/python3.8/dist-packages/keyboard/__init__.py", line 196, in init
_os_keyboard.init()
File "/usr/local/lib/python3.8/dist-packages/keyboard/_nixkeyboard.py", line 113, in init
build_device()
File "/usr/local/lib/python3.8/dist-packages/keyboard/_nixkeyboard.py", line 109, in build_device
ensure_root()
File "/usr/local/lib/python3.8/dist-packages/keyboard/_nixcommon.py", line 174, in ensure_root
raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.
When I attempt to solve that error by entering this, sudo /bin/python3 /home/bhrz/Scripts/Python/Mouse/main.py, it outputs:
Traceback (most recent call last):
File "/home/bhrz/Scripts/Python/Mouse/main.py", line 2, in <module>
import mouse
ModuleNotFoundError: No module named 'mouse'
I have looked for answers, and some were to do the above, which as you can see, has resulted in failure, and another said to do sudo su then run the script--which also failed, with the same output as above.
Please help me figure out what the problem is.
I do have unintentionally 3 versions of python installed: 2.7, 3.8.10, and 3.9.5. I personally installed Python 3.9.5. I don't use 2.7, but it was installed with the python-dev
On Python 3.9.5, the keyboard module isn't recognized, but on Python 3.8.10, it is.
I have found the answer to my problem. The thread: Python can't find module when started with sudo 's second answer fixed my problem.
Instead of running sudo python3(/3.8) myScriptName.py, run sudo -E python3(/3.8) myScriptName.py.
Thank you, Nima for attempting to help me!
Use sudo /bin/python3.8 /home/bhrz/Scripts/Python/Mouse/main.py as you said:
On Python 3.9.5, the keyboard module isn't recognized, but on Python 3.8.10, it is.
python3 has been replaced when you installed python3.9.5. So it belongs to python 3.9.5. You need to use python3.8 in order to execute your script in python 3.8.10 environment.

Spyder IDE working fine, then crashed and won't load back up

Let me preface this by saying I downloaded Spyder as part of the automatic installation of Anaconda about 2 months ago.
I was working on a web scraper in Spyder (i've written a few scrappers/files in Spyder before and run them with no issue). However I accidentally dragged my file so that everything behind it was phased out, and tried to run my file. It told me that I dragged the file out of my IPython environment, so I quit the application and tried to run it back up, hoping it would reconnect.
I've tried to open the application back up, and all I get is the spyder icon, followed by nothing. I did the command line Spyder --reset and got this:
C:\Users\captainhukk>spyder --reset, and this is what I get in return:
Traceback (most recent call last):
File "C:\Anaconda2\Scripts\spyder-script.py", line 2, in <module>
start_app.main()
File "C:\Anaconda2\lib\site-packages\spyderlib\start_app.py", line 114, in main
from spyderlib import spyder
File "C:\Anaconda2\lib\site-packages\spyderlib\spyder.py", line 155, in <module>
from spyderlib.utils.environ import WinUserEnvDialog
File "C:\Anaconda2\lib\site-packages\spyderlib\utils\environ.py", line 17, in <module>
from spyderlib.widgets.dicteditor import DictEditor
File "C:\Anaconda2\lib\site-packages\spyderlib\widgets\dicteditor.py", line 39, in <module>
from spyderlib.widgets.dicteditorutils import (sort_against, get_size,
File "C:\Anaconda2\lib\site-packages\spyderlib\widgets\dicteditorutils.py", line 78, in <module>
import bs4
File "C:\Anaconda2\lib\site-packages\bs4\__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "C:\Anaconda2\lib\site-packages\bs4\builder\__init__.py", line 314, in <module>
from . import _html5lib
File "C:\Anaconda2\lib\site-packages\bs4\builder\_html5lib.py", line 70, in <module>
class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
AttributeError: 'module' object has no attribute '_base'
Any ideas on what to do to fix this issue? I am god awful at working with windows (always used a mac), and have been searching for answers for two hours now and feel completely lost.
It seems there is an issue in the html5library. Try to install the version 1.0b8, probably with (I encountered the same problem but on Linux) :
pip install --upgrade html5lib==1.0b8

Python throws exception on import using pgu with pygame

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.

"AttributeError: fileno" when attemping to import from pyevolve

I just installed Pyevolve using easy_install and I am getting errors trying to run my first program. I first tried copy and pasting the source code of the first example but this is what I receive when I attempt to run it:
Traceback (most recent call last):
File "/home/corey/CTest/first_intro.py", line 3, in
from pyevolve import G1DList
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/init.py", line 15, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Consts.py", line 240, in
import Selectors
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Selectors.py", line 12, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/GPopulation.py", line 11, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/FunctionSlot.py", line 14, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Util.py", line 20, in
AttributeError: fileno
I am running python 2.6 on Fedora 11 X86_64.
Edit: After looking into it more if I run python from the command line it works but it only fails when I'm running IDLE.
Have you tried to check out the Development version ? It's near of the RC1, so it is stable right now:
svn co https://pyevolve.svn.sourceforge.net/svnroot/pyevolve/trunk pyevolve
Your problem seems to be the paths, try uncompressing the "egg" file and put the "pyevolve" directory in the site-packages or inside your application directory.

Categories