Python AttributeError: 'module' object has no attribute 'Goslate'

1.4k Views Asked by At

I am trying Goslate: Free Google Translate API. I installed goslate using sudo pip install goslate

I wrote a simple program and executed it using python getbn.py command in my terminal.

Here is the code inside getbn.py:

import goslate
gs = goslate.Goslate()
print(gs.translate('hello world', 'bn'))

After executing the command python getbn.py I got the following errors:

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'

Then I tried to run the program by executing python3 getbn.pycommand, and I found the following errors:

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'

How do I fix it? And why are there two different types of erros?

2

There are 2 best solutions below

1
On BEST ANSWER

You have a file called goslate.py in your Desktop folder

File "/home/ubuntu/Desktop/goslate.py", line 2, in <module>
      ^^^^^^^^^^^^^^^^^^^^

This is not the module you installed using pip and it's getting in the way of the import.

0
On

You May have simple installed goslate, but you may be using different virtual env. Try to switch to that virtual env, and then run again.