py-googletranslation icon indicating copy to clipboard operation
py-googletranslation copied to clipboard

ImportError: cannot import name 'TranslatedPart' from 'googletrans.models'

Open jrabensc opened this issue 4 years ago • 6 comments
trafficstars

Describe the bug Import error when package is imported: Import Error: cannot import name 'TranslatedPart' from 'googletrans.models'

To Reproduce Install and import pygoogletranslation

!pip install pygoogletranslation
import pygoogletranslation
ModuleNotFoundError: No module named 'googletrans'

Package googletrans seems to be missing.

Install googletrans

!pip install googletrans
import pygoogletranslation
ImportError: cannot import name 'TranslatedPart' from 'googletrans.models' (/usr/local/lib/python3.7/dist-packages/googletrans/models.py)

Expected behavior No import error

Desktop (please complete the following information):

  • Happens both on Google Colab and local Arch Linux installation
  • Python 3.7.10 (Google Colab), Python 3.9.2 (local), pygoogletranslation 2.0.6

jrabensc avatar Apr 16 '21 11:04 jrabensc

I have the same issue in environment:

  • Python 3.8.7
  • pygoogletranslation 2.0.6
  • Windows 10 x64

This seems to be an issue with version 2.0.6 as version 2.0.5 works correctly on my platform.

Kravcu avatar Apr 24 '21 08:04 Kravcu

ImportError: cannot import name 'TranslatedPart' from 'googletrans.models'

lonngxiang avatar May 21 '21 04:05 lonngxiang

I am facing the same issue, unable to import the package

Namyalg avatar Jul 31 '21 15:07 Namyalg

try to install googletrans 4.0.0-rc1, because in this version there found TranslatedPart class on models.py

pip install googletrans==4.0.0-rc1

it works on my environment -pygoogletranslation 2.0.6 -Python 3.8.5 -Windows 10 x64

martinpmt avatar Aug 08 '21 16:08 martinpmt

faced the same issue and had solved it. the error info : ImportError: cannot import name 'TranslatedPart' from 'googletrans.models'

try to change the package code in **\Lib\site-packages\pygoogletranslation\translate.py line 19 before: from googletrans.models import Translated, Detected

changed: from pygoogletranslation.models import Translated, Detected

Agan0525 avatar Nov 25 '21 09:11 Agan0525

  1. cd the following path

YOUR PYTHON INSTALL PATH /lib/site-packages/pygoogletranslation/utils.py


  1. comment the code

from googletrans.models import TranslatedPart #about 8th line


  1. write new import

from pygoogletranslation.models import TranslatedPart


Qu-Dasheng avatar Feb 20 '22 03:02 Qu-Dasheng