无法导入 freegames python 包:AttributeError:模块“集合”没有属性“序列”

Him*_*dar 9 python pip attributeerror python-3.10

Python版本:3.10

\n

我试图使用以下 pip 命令安装freegames python 包

\n
C:\\Users\\praty>pip install freegames\nDefaulting to user installation because normal site-packages is not writeable\nCollecting freegames\n  Downloading freegames-2.3.2-py2.py3-none-any.whl (108 kB)\n     |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 108 kB 504 kB/s\nInstalling collected packages: freegames\nSuccessfully installed freegames-2.3.2\n
Run Code Online (Sandbox Code Playgroud)\n

但是在我的 python 环境中导入相同的内容时,我收到了这个错误

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

我该如何解决同样的问题?

\n

phd*_*phd 15

在相当长的一段时间里Sequence,可以从以下位置导入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"
Run Code Online (Sandbox Code Playgroud)

从 Python 3.7 开始,出现了一个警告,该类已移至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
Run Code Online (Sandbox Code Playgroud)

在 Python 3.10 中,这变成了一个错误:

$ 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"
Run Code Online (Sandbox Code Playgroud)

向作者报告问题freegames。降级到 Python 3.9。了解您永远不应该如此快地升级到最新和最好的版本。