我按照python在线文档(21.12.3)中的示例进行练习。当我尝试使用run Module(F5)运行我的脚本时,我总是得到一个导入错误。但是如果我直接在IDLE命令行中输入它们,python不会报错。我不确定我做错了什么。
我使用的python版本是win32上的Python 3.4.1 (v3.4.1:c0e311e010fc,2014年5月18日,10:38:22) MSC v.1600 32位(英特尔)
脚本是
import http.client
conn = http.client.HTTPConnection("192.168.1.2", 8080)
conn.request("GET", "/index.html")
r1 = conn.getresponse()
print(r1.status, r1.reason)
conn.close()
错误消息是
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 "D:\User\Downloads\http.py", line 1, in <module>
import http.client
File "D:\User\Downloads\http.py", line 1, in <module>
import http.client
ImportError: No module named 'http.client'; 'http' is not a package
发布于 2018-07-27 03:55:13
我也有同样的问题。在我的例子中,同一文件夹中还有另一个名为http.py的文件。我刚给它改名了,问题解决了。
https://stackoverflow.com/questions/24880147
复制相似问题