AttributeError: 'module' object has no attribute 'random' when running python in Atom
AttributeError: 'module' object has no attribute 'random' when running python in Atom
我的代码是:
import random
import numpy
z = numpy.zeros(5)
print(z)
d = random.random()
错误是:
Traceback (most recent call last):
File "/Users/wjxiz/Documents/et5/bigdata/test.py", line 6, in <module>
d = random.random()
AttributeError: 'module' object has no attribute 'random'
我已经在 Atom 中安装了 "scripts" 到 运行 脚本。
我通过 Homebrew 安装了我的 python3,我的路径是:
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/TeX/texbin
当我在终端输入 which python3 和 which python 时:
/usr/local/bin/python3
/usr/bin/python
我可以运行正常编码,但是当我随机导入时,出现问题。
很可能您已将其中一个文件命名为 random.py
,因此 Atom 导入了该文件,而不是 python 随机模块
创建 python 文件时,python 文件名中没有 random.py 或 numpy.py。
我的代码是:
import random
import numpy
z = numpy.zeros(5)
print(z)
d = random.random()
错误是:
Traceback (most recent call last):
File "/Users/wjxiz/Documents/et5/bigdata/test.py", line 6, in <module>
d = random.random()
AttributeError: 'module' object has no attribute 'random'
我已经在 Atom 中安装了 "scripts" 到 运行 脚本。 我通过 Homebrew 安装了我的 python3,我的路径是:
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/TeX/texbin
当我在终端输入 which python3 和 which python 时:
/usr/local/bin/python3
/usr/bin/python
我可以运行正常编码,但是当我随机导入时,出现问题。
很可能您已将其中一个文件命名为 random.py
,因此 Atom 导入了该文件,而不是 python 随机模块
创建 python 文件时,python 文件名中没有 random.py 或 numpy.py。