运行python发生错误:AttributeError: partially initialized module ‘googletrans’ has no attribute ‘translate’ (most likely due to a circular import)

最近在运行一个运用谷歌翻译的python,发生了一下错误:

Traceback (most recent call last): File “/root/newcode/python/googletrans.py”, line 1, in import googletrans as gt File “/root/newcode/python/googletrans.py”, line 4, in print(gt.translate(“Hello, How are you?”, “ko”)) AttributeError: partially initialized module ‘googletrans’ has no attribute ‘translate’ (most likely due to a circular import)

这个错误的原因可能是您的Python文件名和一个Python库的名称相同了,导致Python解释器在导入这个库时出现了错误。具体来说,您的Python文件名为googletrans.py,而您尝试导入了一个名为googletrans的库,这可能会导致Python解释器混淆两者之间的名称,从而出现错误。 为了解决这个问题,您可以尝试将您的Python文件重命名为一个不同的名称,例如my_googletrans.py,然后在您的Python文件中使用正确的库名称来导入googletrans

把 googletrans.py 重新修改了名字,终于运行没问题了。

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注