ModuleNotFoundError: нет модуля с именем «google» - Python & Google TTS - PullRequest
0 голосов
/ 21 января 2020

У меня есть командный файл, который генерирует файлы WAV, используя Python и Google TTS. Этот сценарий оболочки работает нормально на Windows 10. Мне нужно запустить сценарий на веб-сервере Linux (как сценарий оболочки), но я получаю сообщение об ошибке ModuleNotFoundError: No module named 'google'

Запуск help('modules') в Оболочка Python дает мне следующие установленные модули Google:

google_auth_httplib2
googleapiclient
googlesearch

Запуск pip install --upgrade google дает мне:

Collecting google
  Using cached https://files.pythonhosted.org/packages/81/51/36af1d18648574d13d8f43e863e95a97fe6f43d54a13fbcf272c638c10e9/google-2.0.3-py2.py3-none-any.whl
Collecting beautifulsoup4 (from google)
  Using cached https://files.pythonhosted.org/packages/cb/a1/c698cf319e9cfed6b17376281bd0efc6bfc8465698f54170ef60a485ab5d/beautifulsoup4-4.8.2-py3-none-any.whl
Collecting soupsieve>=1.2 (from beautifulsoup4->google)
  Using cached https://files.pythonhosted.org/packages/81/94/03c0f04471fc245d08d0a99f7946ac228ca98da4fa75796c507f61e688c2/soupsieve-1.9.5-py2.py3-none-any.whl
Installing collected packages: soupsieve, beautifulsoup4, google
Successfully installed beautifulsoup4-4.8.2 google-2.0.3 soupsieve-1.9.5

Но у меня все еще есть только три упомянутых модуля над. , Когда я запускаю скрипт sudo -u www-data sh testfile.sh, я получаю следующую ошибку:

Traceback (most recent call last):
  File "TTSA.py", line 37, in <module>
    f'<speak>{speech}</speak>'
  File "TTSA.py", line 9, in synthesize_ssml
    from google.cloud import texttospeech
ModuleNotFoundError: No module named 'google'

Вот скрипт Python:

import sys

filename = str(sys.argv[1])
speech = str(sys.argv[2])

def synthesize_ssml(ssml):
    import os
    os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'creds.json'
    from google.cloud import texttospeech
    client = texttospeech.TextToSpeechClient()

    input_text = texttospeech.types.SynthesisInput(ssml=ssml)

    # Note: the voice can also be specified by name.
    # Names of voices can be retrieved with client.list_voices().
    voice = texttospeech.types.VoiceSelectionParams(
        language_code='en-GB',
        name='en-GB-Wavenet-A'
        #ssml_gender=texttospeech.enums.SsmlVoiceGender.MALE
        )

    audio_config = texttospeech.types.AudioConfig(
        audio_encoding=texttospeech.enums.AudioEncoding.LINEAR16,
        sample_rate_hertz=8000,
        speaking_rate=1.0
        #pitch=2
        )

    response = client.synthesize_speech(input_text, voice, audio_config)

    # The response's audio_content is binary.
    with open(f'{filename}.wav', 'wb') as out:
        out.write(response.audio_content)
        print(f'Audio content written to file {filename}.wav')

synthesize_ssml(
    f'<speak>{speech}</speak>'
    )

Работающие версии:

$ pip -V
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.7)
$ pip2 -V
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.7)
$ pip3 -V
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

python3 .6 модули Google:

google_auth_httplib2
google_oauth2_tool
googleapiclient
googlesearch

python3 .7 модули Google:

google_auth_httplib2
googleapiclient
googlesearch
...