只需在windows上安装python 3,并使用命令"python“在终端上启动它。然后我犯了一个错误:
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'
>>>
(原始截图)
我不明白为什么我会犯这个错误。
发布于 2022-10-12 07:21:11
造成此问题的原因是pyreadline
安装时将过时的包作为可导入的包呈现出来。由于这为Windows提供了readline
模块,默认的site
模块将能够导入它并触发错误。这个过时且不再维护的包试图从不推荐的位置collections.abc.Callable
( collections.Callable
,它将在Python3.10下失败 )导入完全移除,因为被废弃的导入已经是完全移除了。
要解决这个问题,只需卸载pyreadline
包,如果需要由readline提供的功能,则安装pyreadline3
包,该软件包目前正在维护(2022年),并将提供该软件包所期望的功能。
请务必确保在安装pyreadline
之前先卸载pyreadline3
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.
>>>
请注意,如果pyreadline
和pyreadline3
包同时安装在相同的readline
环境/安装中,则可能会发生包冲突,因为这两个包都提供了readline
模块。
或者,按照这句话的建议去做,这是在关于BeautifulSoup的问题下发布的,因为还有其他被广泛使用的Python包没有及时纠正这个不推荐的导入。
发布于 2022-10-12 04:56:20
试一试
BeautifulSoup AttributeError 'collections‘没有属性’可调用‘
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
https://stackoverflow.com/questions/74034049
复制相似问题