栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

[解决方法]AttributeError: module ‘numpy‘ has no attribute ‘loadtxt‘

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[解决方法]AttributeError: module ‘numpy‘ has no attribute ‘loadtxt‘

问题介绍

在pycharm中写了很普通的一段代码:

import numpy as np

with open('泰坦尼克号数据3.csv', encoding='utf-8') as f:
    array = np.loadtxt(f, str, delimiter=',', encoding='utf-8')
    array_title = array[0]

print(array)

在Jupyter中能完美运行,但在Pycharm中不能运行,会报错:

AttributeError: module 'numpy' has no attribute 'loadtxt'
问题分析

可以肯定的是,numpy是有loadtxt属性的,那这里为什么会报错呢?原来,我在Pycharm新建的py文件的文件名也叫numpy,和安装的库名冲突了。

解决方法

在Pycharm中把自己新建的py文件改个名字就行啦。

经验总结

以后像这种:AttributeError: module '(?????)' has no attribute '(?????)'类型的错误,都是由自己新建的py文件名和引用的库函数重名导致的。换个名字即可排除错误。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/499319.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号