Python AttributeError: 'module' object has no attribute xxxx

错误 -- https://blog.csdn.net/qq_34638161/article/details/80698786

AttributeError: 'module' object has no attribute 'expressions'

if PANDAS_VERSION >= '0.20.0':
    from pandas.util import cache_readonly
    pd.set_option('compute.use_numexpr', False)
else:
    from pandas.util.decorators import cache_readonly
    pd.computation.expressions.set_use_numexpr(False)

解决方法:(可行)

conda update dask 


https://www.cnblogs.com/zhangtaosx/p/7352481.html  (方法可行)

注意:tensorflow升级1.0会出现一些bug ,这里简单叙述下解决方式。

1.AttributeError: module ‘pandas’ has no attribute ‘computation’

办法:conda update dask

2.AttributeError: ‘module’ object has no attribute ‘mul’

办法:tf.multiply替代tf.mul

3.AttributeError: ‘module’ object has no attribute ‘sub’

办法: 用tf.subtract替代tf.sub

4.AttributeError: ‘module’ object has no attribute ‘neg’

办法:用tf.negative替代tf.neg

5.出现一些其他问题可以百度,这里不列举。什么修改全局变量(只是名称不同)


https://www.baidu.com/link?url=cw_JYCqXoG1GH2m1BZIqJ-o0BCNPnATKDHzba3VhUWxIqRy9an4VSQgYBx7R11tKWlVVC3M3X8-6Lcib4kdYD_&wd=&eqid=8242c72b0000ec66000000065b2874b0

import six
print six.__version__

import plotly
print plotly.__version__

pip install --upgrade six

https://stackoverflow.com/questions/4232455/numpy-load-raises-attributeerror-module-object-has-no-attribute-expr

I think you must have another file named parser.py somewhere in your files (the ones that Python can find). It is making it so that Python finds the wrong parser module. Look around and see if that is the case. It could be a parser.so file too.

Try going into an interactive session and typing:

import parser
print parser.__file__

Hopefully, that will tell you where the troublesome file is located.

https://blog.csdn.net/libertine1993/article/details/54232474

原因:

导致在这个问题的原因是你的模块名和你要引用的类或方法或变量的名字重了。说通俗点就是,python脚本名字(模块名)和你要引用的内容(模块内的类,变量等)的名字重复了,导致你原本“类->属性/方法”的引用意图被解析为了"模块->属性”的引用意图。当模块下面没有这个属性,就抛出了这个错误。解决办法是换不重复的命名。

根本杜绝问题的方法是确保模块名(即文件名)不和模块内要引用的内容重复。这里把GetOnePara.py重命名为fGetOnePara.py以区分模块和模块内的类。此外还需要 修改GetOnePara的类调用代码, 为其指定命名空间(其所属的模块名),即:

  1. import GetOnePara  
  2. urlDic = GetOnePara.getReqUrlDic() #模块名和类名重合,加上未指定明明空间,导致解析的结果和实际意图不服  

改为 (模块名.类名.属性名 的形式)

  1. import fGetOnePara #修改了模块名  
  2. urlDic = fGetOnePara.GetOnePara.getReqUrl() #指定命名空间  

https://www.cnblogs.com/tl542475736/p/5614058.html

最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attribute 'xxx'"。这其实是.pyc文件存在问题。

问题定位:

查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件

问题解决方法:

1. 命名py脚本时,不要与python预留字,模块名等相同

2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值