[英]AttributeError: 'module' object has no attribute 'random' when running python in Atom
my code is: 我的代码是:
import random
import numpy
z = numpy.zeros(5)
print(z)
d = random.random()
and the error is: 错误是:
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'
I hava already installed "scripts" to run scripts in atom. 我已经安装了“脚本”以在atom中运行脚本。 I installed my python3 by Homebrew and my path is:
我通过Homebrew安装了python3,我的路径是:
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/TeX/texbin
when I type which python3 and which python in terminal: 当我在终端中键入哪个python3和哪个python时:
/usr/local/bin/python3
/usr/bin/python
I can run normal code correctly but when I import random, problem occurs. 我可以正常运行常规代码,但是当我随机导入时,会出现问题。
您很可能已将文件之一命名为random.py
,因此Atom会导入该文件,而不是python random模块
创建python文件时,不要将Python文件名带有random.py或numpy.py。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.