Unable to import freegames python package : AttributeError: module 'collections' has no attribute 'Sequence'
Asked Answered
J

5

11

Python version : 3.10

I was trying to install the freegames python package using the following pip command

C:\Users\praty>pip install freegames
Defaulting to user installation because normal site-packages is not writeable
Collecting freegames
  Downloading freegames-2.3.2-py2.py3-none-any.whl (108 kB)
     |████████████████████████████████| 108 kB 504 kB/s
Installing collected packages: freegames
Successfully installed freegames-2.3.2

But while importing the same on my python environment I was getting this error

C:\Users\praty>python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import freegames
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\praty\AppData\Roaming\Python\Python310\site-packages\freegames\_init_.py", line 61, in <module>
    from .utils import floor, line, path, square, vector
  File "C:\Users\praty\AppData\Roaming\Python\Python310\site-packages\freegames\utils.py", line 77, in <module>
    class vector(collections.Sequence):
AttributeError: module 'collections' has no attribute 'Sequence'

How do I resolve the same?

Jule answered 16/10, 2021 at 14:28 Comment(3)
Do you happen to have a file named collections? (Which overrides the built-in one)Inharmonious
in my working directory? noJule
Version 2.4.0 was released today and supports Python 3.10. Refer to the "Free Python Games Issue Tracker" in the docs at grantjenks.com/docs/freegames/#references to file bugs in the future.Loralorain
T
17

For quite some time Sequence was importable from collections:

$ python2.7 -c "from collections import Sequence"
$ python3.4 -c "from collections import Sequence"
$ python3.5 -c "from collections import Sequence"
$ python3.6 -c "from collections import Sequence"

Starting from Python 3.7 there was a warning the class has been moved to collections.abc:

$ python3.7 -c "from collections import Sequence"
-c:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
$ python3.8 -c "from collections import Sequence"
<string>:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
$ python3.9 -c "from collections import Sequence"
<string>:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working

In Python 3.10 this became an error:

$ python3.10 -c "from collections import Sequence"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'Sequence' from 'collections' (/home/phd/.local/lib/python3.10/collections/__init__.py)
$ python3.10 -c "from collections.abc import Sequence"

Report the problem to the author of freegames. Downgrade to Python 3.9. Learn that you should never be so fast to upgrade to the latest and greatest versions.

Townes answered 16/10, 2021 at 17:48 Comment(0)
P
1

This way can solved my issue.

import collections

collections.Mapping = collections.abc.Mapping

collections.Sequence = collections.abc.Sequence

Pearl answered 16/12, 2023 at 18:28 Comment(0)
M
1

this is caused by the fact that you are using an old version od Django which is incompatible with python3.10.

You can either downgrade your python or upgrade your django (the latter can require a lot of changes on your code).

try this

sudo vim /usr/lib/python3.10/collections/__init__.py

search for line

from _weakref import proxy as _proxy

right below it, just paste

# my changes
#--------------

import collections
collections.Mapping = collections.abc.Mapping
collections.Sequence = collections.abc.Sequence

#--------------
Mabelmabelle answered 1/4 at 16:2 Comment(0)
C
0
$ diff -ua X.py.orig X.py
...
-import collections
+try:
+    import collections.abc as collections
+except ImportError:
+    import collections
...

Works like a charm here. Thanks Siavash

Creamer answered 24/5 at 10:52 Comment(0)
F
-1

This issue has been resolved

import collections.abc as collections

module 'collections' has no attribute 'Mapping', issue on MACOS for SDK installation

Forestall answered 13/10, 2022 at 18:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.