简体   繁体   English

AttributeError:在Atom中运行python时,“模块”对象没有属性“随机”

[英]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.

相关问题 AttributeError: &#39;module&#39; 对象没有运行 pip 的属性 &#39;python_implementation&#39; - AttributeError: 'module' object has no attribute 'python_implementation' running pip 如何修复AttributeError:在Google Cloud Interactive Shell中运行python时,'module'对象没有属性'Client' - How to fix AttributeError: 'module' object has no attribute 'Client' when running python in Google Cloud Interactive Shell Python:AttributeError:&#39;module&#39;对象没有属性&#39;socketpair&#39; - Python: AttributeError: 'module' object has no attribute 'socketpair' Python AttributeError:“模块”对象没有属性“获取” - Python AttributeError: 'module' object has no attribute 'get' python - AttributeError:&#39;module&#39;对象没有属性&#39;lock&#39; - python - AttributeError: 'module' object has no attribute 'lock' Python错误:AttributeError:&#39;module&#39;对象没有属性 - Python error: AttributeError: 'module' object has no attribute Python AttributeError:“模块”对象没有属性“ Goslate” - Python AttributeError: 'module' object has no attribute 'Goslate' Python:AttributeError:“模块”对象没有属性“ randrange” - Python: AttributeError: 'module' object has no attribute 'randrange' python - AttributeError:&#39;module&#39;对象没有属性 - python - AttributeError: 'module' object has no attribute Python-AttributeError:“模块”对象没有属性“ QueryFrame” - Python - AttributeError: 'module' object has no attribute 'QueryFrame'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM