gpt4 book ai didi

python - 导入我的 'random' 文件时脚本失败

转载 作者:行者123 更新时间:2023-12-05 00:44:39 25 4
gpt4 key购买 nike

我一直在学习教程,在按照讲师列出的步骤操作后,我遇到了以下错误:

C:\Users\Angel\Documents\Python Basic> & C:/Users/Angel/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/Angel/Documents/Python Basic/pandaexample.py"
Traceback (most recent call last):
File "c:/Users/Angel/Documents/Python Basic/pandaexample.py", line 3, in <module>
import pandas
File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\__init__.py", line 11, in <module>
__import__(dependency)
File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\numpy\__init__.py", line 152, in <module>
from . import random
File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\numpy\random\__init__.py", line 181, in <module>
from . import _pickle
File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\numpy\random\_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "_bit_generator.pxd", line 14, in init numpy.random.mtrand
File "_bit_generator.pyx", line 40, in init numpy.random._bit_generator
File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\secrets.py", line 20, in <module>
from random import SystemRandom
File "c:\Users\Angel\Documents\Python Basic\random.py", line 2, in <module>
random.randint(1, 10)
AttributeError: partially initialized module 'random' has no attribute 'randint' (most likely due to a circular import)
这是代码
import time
import os
import pandas

while True:
if os.path.exists("files/temps_today.csv"):
data = pandas.read_csv("files/temps_today.csv")
print(data.mean())
else:
print("file does not exist")
time.sleep(10)

请,非常感谢您的帮助
PS:我成功安装了 Pandas

最佳答案

这里的问题是您有一个名为 C:\Users\Angel\Documents\Python Basic\random.py 的文件。 , 由 /lib/email/utils.py 导入而不是内置 random .

来自 the docs :

The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended.



如果您重命名此 random.py 应该修复此错误.

关于python - 导入我的 'random' 文件时脚本失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59767337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com