如何修复 AttributeError:部分初始化的模块? [英] How to fix AttributeError: partially initialized module?

查看:64
本文介绍了如何修复 AttributeError:部分初始化的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行我的脚本,但不断收到此错误:

I am trying to run my script but keep getting this error:

File ".\checkmypass.py", line 1, in <module>
  import requests 
line 3, in <module>
  response = requests.get(url) 
AttributeError: partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import)

我该如何解决?

推荐答案

你检查过文件名了吗?它不应该与您要导入的模块(圆形)相同.还要检查 URL 和您正在使用的包.很可能是由于循环导入"指的是一个文件(模块),它依赖于其他东西,并且在它已经被导入时试图被导入.然后在检查时,你应该有这样的东西:

Have you checked the name of the file? it should not be as same as the module you are importing (circular). Also check the URL and the package you are using. "Most likely due to a circular import" refers to a file (module) which has got a dependency on something else and is trying to be imported while it's already been imported. Then while checked, you should have something like this:

import requests

r = requests.get("http://google.com")       
print(r.status_code)

# 200

这篇关于如何修复 AttributeError:部分初始化的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆