![](/img/trans.png)
[英]How to fix the error 'AttributeError: module 'board' has no attribute 'SCK'' I am using raspberry pi
[英]How to fix this error "AttributeError: module 'socket' has no attribute 'gethostname'"
我正在尝试执行此脚本以获取我的笔记本电脑的主机名
我使用 Windows7 64 位和 Python 3.6.4
我已经在 Python IDE 中尝试过这段代码,并且成功了。 这个错误发生在 PyCharm 中
import socket
c = socket.gethostname()
print(c)
你有什么解决方案?
您的文件很可能被命名为socket.py
。
然后当你import socket
,它会导入当前文件而不是 python socket 模块。
将您的文件重命名为另一个名称和rm -rf socket.pyc
(以删除先前执行生成的已编译字节码)。
当我导入 matplotlib.pyplot 时,出现此错误 - AttributeError: module 'socket' has no attribute 'gethostname'
但是我已经创建了一个文件 socket.py 一次,我删除了这个文件,这个问题是固定的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.