gpt4 book ai didi

python 3 : AttributeError: 'module' object has no attribute '__path__' using urllib in terminal

转载 作者:太空狗 更新时间:2023-10-29 17:47:41 25 4
gpt4 key购买 nike

我的代码在 PyCharm 中运行完美,但我在尝试在终端中打开它时收到错误消息。我的代码有什么问题,或者我哪里出错了?

import urllib.request
with urllib.request.urlopen('http://python.org/') as response:
html = response.read()
print(html)

终端输出:

λ python Desktop\url1.py
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "Desktop\url1.py", line 1, in <module>
import urllib.request
File "C:\Users\Przemek\Desktop\urllib.py", line 1, in <module>
import urllib.request
ImportError: No module named 'urllib.request'; 'urllib' is not a package

最佳答案

您调用了一个文件C:\Users\Przemek\Desktop\urllib.py,您需要重命名它。您正在从中导入而不是实际的模块。重命名 C:\Users\Przemek\Desktop\urllib.py 并删除任何 C:\Users\Przemek\Desktop\urllib.pyc

这不是您正在运行的文件,但您在同一目录中有该文件,因此 python 首先检查当前目录,因此出现错误。

关于 python 3 : AttributeError: 'module' object has no attribute '__path__' using urllib in terminal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30261860/

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