Trying to get Python Arcade to work on Ubuntu - python

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.

Related

what could be the reason for the importerror [duplicate]

This question already has answers here:
It Keeps showing this. What Should I do? [closed]
(2 answers)
Closed 2 years ago.
I am trying to train a model of CNN.
When I run the code, it returns following error:
Traceback (most recent call last):
File "train_network.py", line 5, in <module>
import matplotlib
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/matplotlib/__init__.py", line 138, in <module>
from . import cbook, rcsetup
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/matplotlib/cbook/__init__.py", line 32, in <module>
import numpy as np
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/numpy/core/__init__.py", line 102, in <module>
from . import _dtype_ctypes
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/numpy/core/_dtype_ctypes.py", line 25, in <module>
import _ctypes
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
ImportError generally refers to an import library required for execution is not present within executing systems.
Few possible cases to look for.
In a general case, your system where py is running is missing this package.
In Spark(general-purpose computing cluster), if you are running this cnn then one of your worker node could be missing file/package.
Bugs: In Py bug tracker this bug reported for some package like Pipenv. This resolved as per https://bugs.python.org/issue40367 Just upgrade your used libs to stable version
If its path issue then check for which python you have installed library and which version you are using. I.e. there could be multiple python version in your systems. Python2 pkgs repo and Python3 pkgs repo loc are different.
If its simple OS path issue - https://jackiechen.org/2016/01/13/importerror-libffi-so-6-cannot-open-shared-object-file-no-such-file-or-directory/
Try to just use the latest version or switch to more stable version packages to avoid this error.

Python shell working differently on different location in the same machine inside same virtual environment

I have a cloud instance of a Linux machine (openSuSE) with multiple users.
I have created a virtual environment and installed all my required libraries (including Klein).
I have two users "a" and "b".
While logged in as "a" and inside virtualenv, when I open python shell at home directory and type
import klein
it imports normally.
Now when I change directory to
/home/b/
and run the same (open python shell, import klein) while being in the same virtualenv, it gives me an error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/a/.local/lib/python3.6/site-packages/klein/__init__.py", line 3, in <module>
from klein._plating import Plating
File "/home/a/.local/lib/python3.6/site-packages/klein/_plating.py", line 16, in <module>
from .app import _call
File "/home/a/.local/lib/python3.6/site-packages/klein/app.py", line 19, in <module>
from twisted.internet import endpoints, reactor
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/endpoints.py", line 58, in <module>
from twisted.protocols.tls import TLSMemoryBIOFactory
File "/home/a/.local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 63, in <module>
from twisted.internet._sslverify import _setAcceptableProtocols
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 158, in <module>
verifyHostname, VerificationError = _selectVerifyImplementation()
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 141, in _selectVerifyImplementation
from service_identity import VerificationError
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/__init__.py", line 7, in <module>
from . import cryptography, pyopenssl
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/cryptography.py", line 16, in <module>
from .exceptions import SubjectAltNameWarning
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/exceptions.py", line 21, in <module>
#attr.s
AttributeError: module 'attr' has no attribute 's'
Command "which python" gives same address at both location which is my virtualenv python address and that should be expected.
But what causes this weird python shell behavior.
Thank you
I solved it and a very shameful reason caused the error.
One of the modules Twisted uses is "attr" module. I had named one of my files attr.py and that is what was causing all the error.
I myself am not deleting this question if moderation has no problem, maybe somebody like me might be stuck at the same situation. It may help them.
Never name your python files same as that of any standard module unless overriding.
Also if your issue persists, then Jean's answer will definitely resolve it.
There can be multiple different Python packages that provide the same Python module. For example, there are at least two packages that provide the attr module:
https://pypi.org/project/attr/
https://pypi.org/project/attrs/
It's possible you've installed the wrong package based on the requirements. You can check what you have installed with pip freeze.

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.

SQLAlchemy import error : import _mysql

I am new at Python and SQLAlchemy and I was trying to play with them a little bit, but whenever I run a test it gives me the following error :
Traceback (most recent call last):
File "/home/zakaria/workspace-python/Jerreb/essai/tejriba.py", line 11, in <module>
engine = create_engine("mysql://root:root#localhost/python")
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-i686.egg/sqlalchemy/engine/__init__.py", line 346, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-i686.egg/sqlalchemy/engine/strategies.py", line 74, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-i686.egg/sqlalchemy/connectors/mysqldb.py", line 64, in dbapi
return __import__('MySQLdb')
File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.5-py2.7-linux-i686.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: /usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.5-py2.7-linux-i686.egg/_mysql.so: undefined symbol: _Py_ZeroStruct
I am working with PyDev.
This is the project architecture:
And these are the libs I have imported :
What is the problem and how can I fix it?
Thanks!
When I got this message, it turned out that, unbeknownst to me, the code was being run in the Python 3 interpreter, instead of Python 2. (This happened because I had installed Ubuntu's libapache2-mod-wsgi-py3 for a different project.) MySQL-python does not yet support Python 3. :'(
I don't know whether WSGI is involved for you, but try making sure you're not running Python 3.

Installing Pandas with Python 2.5 on Windows

I'm trying to get Pandas installed with Python 2.5 on a machine running Windows XP.
The installation seems to finish OK, but when I try
from pandas import *
I get the following error:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "c:\python25\lib\site-packages\pandas-0.7.2-py2.5-win32.egg\pandas\__init__.py", line 24, in <module>
from pandas.stats.api import *
File "c:\python25\lib\site-packages\pandas-0.7.2-py2.5-win32.egg\pandas\stats\api.py", line 7, in <module>
from pandas.stats.moments import *
File "c:\python25\lib\site-packages\pandas-0.7.2-py2.5-win32.egg\pandas\stats\moments.py", line 388, in <module>
rolling_max = _rolling_func(_tseries.roll_max, 'Moving maximum')
File "c:\python25\lib\site-packages\pandas-0.7.2-py2.5-win32.egg\pandas\stats\moments.py", line 379, in _rolling_func
def f(arg, window, min_periods=None, time_rule=None):
File "C:\Python25\Lib\functools.py", line 35, in update_wrapper
getattr(wrapper, attr).update(getattr(wrapped, attr))
AttributeError: 'builtin_function_or_method' object has no attribute '__dict__'
As far as I can tell, I've got all of the dependencies installed correctly, and the problem is something to do with functools.py, which is part of the Python Standard Library(?).
Does anyone have any suggestions, please? Pandas is supposed to work with Python 2.5, so I assume it's a problem with my Python configuration.
Is this the Python distro that came with ArcGIS or Python.org? As discussed on the mailing list this does not seem to be an issue with Python 2.5 per se but potentially your environment

Categories