【Python】AttributeError: module ‘numpy’ has no attribute ‘__version__’
xixuefeng
Python
2024-11-08 10:22:22
1,346 次浏览
Python数据分析
【Python】AttributeError: module ‘numpy’ has no attribute ‘__version__’已关闭评论
安装numpy模块
|
1 2 3 4 5 6 7 8 9 10 |
E:\Python>pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting numpy Downloading https://pypi.tuna.tsinghua.edu.cn/packages/97/9f/da37cc4a188a1d5d203d65ab28d6504e17594b5342e0c1dc5610ee6f4535/numpy-1.21.6-cp37-cp 37m-win_amd64.whl (14.0 MB) ---------------------------------------- 14.0/14.0 MB 26.1 MB/s eta 0:00:00 Installing collected packages: numpy Successfully installed numpy-1.21.6 E:\Python> |
创建python文件,测试一下numpy模块安装是否成功
|
1 2 |
import numpy as np print(np.__version__) |
执行代码报如下错误:
|
1 2 3 4 5 6 7 8 9 |
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe E:/Python/venv/数据分析/numpy/numpy.py Traceback (most recent call last): File "E:/Python/venv/数据分析/numpy/numpy.py", line 1, in <module> import numpy as np File "E:\Python\venv\数据分析\numpy\numpy.py", line 2, in <module> print(np.__version__) AttributeError: module 'numpy' has no attribute '__version__' Process finished with exit code 1 |
错误提示:’numpy’这个模块没有’__version__’这个属性,理论上是不太可能的,因为numpy模块刚刚安装完成,不太可能缺少属性。
仔细看错误输出你会发现,做为只学到皮毛的选手来说,会经常犯一些低级错误,比如这个python文件的文件名,用的名字与引用的模块名相同。
引用模块时的顺序大概是这样:
1:当前目录
2:PYTHONPATH
3:Python安装的默认路径
显然,这个错误在引用模块时,默认引用的是当前路径下的自己。改个名字即可。
|
1 2 3 4 |
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe E:/Python/venv/数据分析/numpy/numpy_study.py 1.21.6 Process finished with exit code 0 |