首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Windows上的Python以‘`AttributeError:模块’集合‘没有属性’可调用‘开始

Windows上的Python以‘`AttributeError:模块’集合‘没有属性’可调用‘开始
EN

Stack Overflow用户
提问于 2022-10-11 20:58:18
回答 2查看 367关注 0票数 0

只需在windows上安装python 3,并使用命令"python“在终端上启动它。然后我犯了一个错误:

代码语言:javascript
运行
复制
C:\Users\User>python
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site.py", line 446, in register_readline
    import readline
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\readline.py", line 34, in <module>
    rl = Readline()
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
    BaseReadline.__init__(self)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
    mode.init_editing_mode(None)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
    self._bind_key('space',       self.self_insert)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
    if not callable(func):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
    return isinstance(x, collections.Callable)
AttributeError: module 'collections' has no attribute 'Callable'
>>>

(原始截图)

我不明白为什么我会犯这个错误。

EN

回答 2

Stack Overflow用户

发布于 2022-10-12 07:21:11

造成此问题的原因是pyreadline安装时将过时的包作为可导入的包呈现出来。由于这为Windows提供了readline模块,默认的site模块将能够导入它并触发错误。这个过时且不再维护的包试图从不推荐的位置collections.abc.Callable ( collections.Callable它将在Python3.10下失败 )导入完全移除,因为被废弃的导入已经是完全移除了。

要解决这个问题,只需卸载pyreadline包,如果需要由readline提供的功能,则安装pyreadline3包,该软件包目前正在维护(2022年),并将提供该软件包所期望的功能。

请务必确保在安装pyreadline之前先卸载pyreadline3

代码语言:javascript
运行
复制
C:\Users\User>python -m pip uninstall pyreadline
Found existing installation: pyreadline 2.1
Uninstalling pyreadline-2.1:
  Would remove:
    c:\users\user\appdata\local\programs\python\python310\lib\site-packages\pyreadline-2.1-py3.10.egg-info
    c:\users\user\appdata\local\programs\python\python310\lib\site-packages\pyreadline\*
    c:\users\user\appdata\local\programs\python\python310\lib\site-packages\readline.py
Proceed (Y/n)? y
  Successfully uninstalled pyreadline-2.1

C:\Users\User>python -m pip install pyreadline3
Collecting pyreadline3
  Downloading pyreadline3-3.4.1-py3-none-any.whl (95 kB)
     ---------------------------------------- 95.2/95.2 kB ? eta 0:00:00
Installing collected packages: pyreadline3
Successfully installed pyreadline3-3.4.1

C:\Users\User>python
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

请注意,如果pyreadlinepyreadline3包同时安装在相同的readline环境/安装中,则可能会发生包冲突,因为这两个包都提供了readline模块。

或者,按照这句话的建议去做,这是在关于BeautifulSoup的问题下发布的,因为还有其他被广泛使用的Python包没有及时纠正这个不推荐的导入。

票数 2
EN

Stack Overflow用户

发布于 2022-10-12 04:56:20

试一试

BeautifulSoup AttributeError 'collections‘没有属性’可调用‘

代码语言:javascript
运行
复制
Navigate to Python310\Lib\site-packages\pyreadline in your file browser.
Open py3k_compat.py in an text editor.
Change the 8th line from which should be return isinstance(x, collections.Callable) to return isinstance(x, collections.abc.Callable).
Save, exit and then retry.

或者重新安装python

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74034049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档