gpt4 book ai didi

python - 导入 asyncio 抛出错误

转载 作者:太空宇宙 更新时间:2023-11-04 00:17:20 25 4
gpt4 key购买 nike

在我的终端中,我想用 asyncio 测试一些东西。这是我所做的:

$ python3.6
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio

这引发了如下错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/__init__.py", line 42, in <module>
tasks.__all__ +
AttributeError: module 'asyncio.tasks' has no attribute '__all__'

为什么会抛出这个错误,我该如何解决? (我以同样的方式检查了我的 python 3.5 解释器并且没有错误,所以库可能已损坏?)

我用 -v 开关运行 Python,在提示符下运行 import asyncio 后产生的输出相当大,所以它在 this GitHub gist 中可用。 .

最佳答案

您的本地安装已损坏。从您提供的 python -v 输出中:

# bytecode is stale for 'asyncio.tasks'
# code object from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py
import 'asyncio.tasks' # <_frozen_importlib_external.SourceFileLoader object at 0x104cf7860>

bytecode is stale 消息意味着 asyncio/tasks.py 文件比伴随的 asyncio/__pycache__/tasks .cpython-36.pyc 文件。这表明某些内容已更改 tasks.py 文件,导致内容与 Python 二进制文件附带的内容不同。

为了比较,兄弟模块 asyncio.events 是从字节码缓存中加载的,它由 Python 安装程序在安装时提供:

# code object from '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/__pycache__/events.cpython-36.pyc'
import 'asyncio.events' # <_frozen_importlib_external.SourceFileLoader object at 0x104ccf4e0>

该模块的代码对象是从 asyncio/__pycache__/events.cpython-36.pyc 文件加载的。

您可以从 OS X installer 重新安装 Python , 但在这一点上我只是捕获了 newer 3.6.5 release相反。

您也可以尝试通过下载 original source from the v3.6.2 tag 来恢复原始内容。 ,但是你必须确保重新生成字节码(运行 sudo python -m compileall/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py),你需要检查任何其他这样的更改文件(尝试 find/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6 -name\*.py -newer/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/__init__.py)

关于python - 导入 asyncio 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50428661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com