无法导入freegames python包:AttributeError:模块'collections'没有属性'Sequence'
Posted
技术标签:
【中文标题】无法导入freegames python包:AttributeError:模块\'collections\'没有属性\'Sequence\'【英文标题】:Unable to import freegames python package : AttributeError: module 'collections' has no attribute 'Sequence'无法导入freegames python包:AttributeError:模块'collections'没有属性'Sequence' 【发布时间】:2021-12-04 08:28:47 【问题描述】:Python 版本:3.10
我正在尝试使用以下 pip 命令安装 freegames python 包
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
但是在我的 python 环境中导入相同的内容时,我遇到了这个错误
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'
我该如何解决?
【问题讨论】:
你碰巧有一个名为 collections 的文件吗? (覆盖内置的) 在我的工作目录中?没有 今天发布了 2.4.0 版本,支持 Python 3.10。请参阅grantjenks.com/docs/freegames/#references 文档中的“免费 Python 游戏问题跟踪器”,以便将来提交错误。 【参考方案1】:在相当长的一段时间内,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"
从 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
在 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"
向freegames
的作者报告问题。降级到 Python 3.9。了解您永远不应该这么快升级到最新最好的版本。
【讨论】:
以上是关于无法导入freegames python包:AttributeError:模块'collections'没有属性'Sequence'的主要内容,如果未能解决你的问题,请参考以下文章
已安装包(Python PIL/Pillow)但我无法导入它
Cannot set up a python SDK at Python 2.7 The SDK seems invalid - Python项目迁移时虚拟环境无法成功导入,致依赖包无法识别的问题
Cannot set up a python SDK at Python 2.7 The SDK seems invalid - Python项目迁移时虚拟环境无法成功导入,致依赖包无法识别的问题