我正在尝试Goslate:免费的Google Translate API。我使用sudo pip install goslate
安装了goslate
我编写了一个简单程序,并在终端中使用python getbn.py
命令执行了该程序。
这是getbn.py
中的代码:
import goslate
gs = goslate.Goslate()
print(gs.translate('hello world', 'bn'))
执行命令
python getbn.py
后,出现以下错误:Traceback (most recent call last):
File "getbn.py", line 1, in <module>
import goslate
File "/home/ubuntu/Desktop/goslate.py", line 2, in <module>
# -*- coding: utf-8 -*-
AttributeError: 'module' object has no attribute 'Goslate'
然后,我尝试通过执行
python3 getbn.py
命令运行该程序,发现以下错误:Traceback (most recent call last):
File "getbn.py", line 1, in <module>
import goslate
ImportError: bad magic number in 'goslate': b'\x03\xf3\r\n'
我如何解决它?为什么会有两种不同类型的错误?
最佳答案
您的goslate.py
文件夹中有一个名为Desktop
的文件
File "/home/ubuntu/Desktop/goslate.py", line 2, in <module>
^^^^^^^^^^^^^^^^^^^^
这不是您使用
pip
安装的模块,它妨碍了导入。