解决“AttributeError: module ‘***‘ has no attribute ‘***‘“ 错误的思路

 遇到如下错误,解决思路一般有两个:包的名字和包的版本。

AttributeError: module '***' has no attribute '***'

1 包的名字

安装包的名字出错了,比如whois,用于查询Whois信息的库。在pypi.org有python-whois和whois两个包,具体信息如下

python-whois包

https://pypi.org/project/python-whois(https://github.com/richardpenman/whois)

whois包

https://pypi.org/project/whois/(https://github.com/DannyCork/python-whois)

用python-whois包查询信息代码如下

import whois

print(whois.whois('csdn.net'))

用whois包查询信息代码如下 

import whois

print(whois.query('csdn.net'))

两块代码极其相似,很容易弄错,所以开发要明确基于什么包在写代码。

2 包的版本

包的每个版本提供接口可能发生改变,比如python-whois包,安装0.9.4版本的,运行上面代码,会报如下错误

AttributeError: module 'whois' has no attribute 'whois'

但安装0.8.0版本的就可以正常运行了。

  • 14
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值