gpt4 book ai didi

python - 为什么我会收到 pylint 错误 : Module 'socket' has no 'gethostname' member (no-member)?

转载 作者:行者123 更新时间:2023-12-05 04:46:45 25 4
gpt4 key购买 nike

我有以下代码示例:

#!/usr/bin/python3
'''Why do I get the pylint error Module 'socket' has no 'gethostname' member (no-member)?'''
import socket
print(socket.gethostname())

它运行良好并打印主机名作为输出。

但是,当我检查 pylint 时出现错误:

% pylint testSocket.py
************* Module testSocket
testSocket.py:7:6: E1101: Module 'socket' has no 'gethostname' member (no-member)

----------------------------------------------------------------------
Your code has been rated at -15.00/10 (previous run: -20.00/10, +5.00)

%

这是一个超精简示例。在我的完整代码中,我使用了其他套接字函数,例如 socket.getfqdn()socket.gethostbyname(nDict['HOST_FQDN']),没有 pylint 问题.

即使在 socket 模块中,它在 Functions 下也包含以下行:

    gethostname() -- return the current hostname

我怎样才能干净地运行 pylint? (不求助于#pylint: disable=E1101)

Python 3.8.2,pylint 2.7.2

最佳答案

现在 pylint 中的某些环境(例如 MacOs)存在问题。作为解决方法,如果您使用 pyenv 安装您的环境,它将重新编译一些包并正常工作。参见 this comment

When I first stumbled over this I made a list to check what the culprits are, and it boiled down to two modules: socket (socket.error, socket.AF_INET, socket.SOCK_STREAM), math (math.log10, math.pi, math.ceil, math.sqrt)

For example, the math.log10 is found in math.pyi (i.e. the stub file) when using command+SHIFT to jump to source.Maybe those stub files are not installed correctly with some installation methods.I'll try to figure out where they should live - if I jump from VScode to the .pyi file, it opens one of the fallback stub files provided by the Pylance plugin for VScode.

关于python - 为什么我会收到 pylint 错误 : Module 'socket' has no 'gethostname' member (no-member)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68719442/

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