ModuleNotFoundError: No module named 'google' - Python & Google TTS - python

I have a batch file that generates wav files using Python and Google TTS. This shell script runs fine on Windows 10. I need to run the script on a Linux web server (as a shell script) but I get the error
ModuleNotFoundError: No module named 'google'
Running help('modules') in a Python shell gives me the following google modules that are currently installed:
google_auth_httplib2
googleapiclient
googlesearch
Running pip install --upgrade google gives me:
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
But I still only have the same three modules mentioned above. . When I run the script sudo -u www-data sh testfile.sh I get the following error:
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'
Here is the Python script:
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>'
)
Versions running:
$ 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 modules:
google_auth_httplib2
google_oauth2_tool
googleapiclient
googlesearch
python3.7 google modules:
google_auth_httplib2
googleapiclient
googlesearch

Related

Getting ModuleNotFoundError: No module named 'azure'

I am using Azure Pipelines and getting the following error:
ImportError: Failed to import test module: QueryUrls
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.8.3/x64/lib/python3.8/unittest/loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "/home/vsts/work/1/s/QueryUrls/__init__.py", line 2, in <module>
import azure.functions as func
ModuleNotFoundError: No module named 'azure'
The error occurs when I run unit tests for an Azure Function written in Python. The code I am runnning in the pipeline (to run the unit tests) is the following:
- script: |
python -m unittest QueryUrls/test_queryurls.py
displayName: 'Test with unittest'
The pipeline was running correctly before I added the above lines. Here is the script that is being called:
# tests/test_httptrigger.py
import unittest
from pathlib import Path
import azure.functions as func
from . import main
#from QueryUrls import my_function
class TestFunction(unittest.TestCase):
def test_my_function(self):
# Construct a mock HTTP request.
req = func.HttpRequest(
method='GET',
body=None,
url='/api/QueryUrls',
params={'name': 'World'})
# Call the function.
resp = my_function(req)
# Check the output.
self.assertEqual(
resp.get_body(),
b'Hello World',
)
if __name__ == '__main__':
unittest.main()
Proper way to do this is to have a requirements txt which has all the dependencies
pip install -r requirements.txt -r requirements-test.txt
add the azure-functions to the requirements-text.txt and run the script at the beginning
Are you sure that azure.function is isntalled on the machine?
Please install it before you run your tests:
script: pip install azure-functions
For pip list on agent I got this:
2020-07-17T12:50:55.7295699Z Generating script.
2020-07-17T12:50:55.7324332Z Script contents:
2020-07-17T12:50:55.7324840Z pip list
2020-07-17T12:50:55.7325214Z ========================== Starting Command Output ===========================
2020-07-17T12:50:55.7366079Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/64166a13-122f-49af-b5af-153c399305d9.sh
2020-07-17T12:50:57.7202987Z ansible (2.9.10)
2020-07-17T12:50:57.7249252Z chardet (2.3.0)
2020-07-17T12:50:57.7250502Z crcmod (1.7)
2020-07-17T12:50:57.7251632Z cryptography (1.2.3)
2020-07-17T12:50:57.7252618Z ecdsa (0.13)
2020-07-17T12:50:57.7253446Z enum34 (1.1.2)
2020-07-17T12:50:57.7254214Z httplib2 (0.9.1)
2020-07-17T12:50:57.7255377Z idna (2.0)
2020-07-17T12:50:57.7256319Z ipaddress (1.0.16)
2020-07-17T12:50:57.7257152Z Jinja2 (2.8)
2020-07-17T12:50:57.7257929Z MarkupSafe (0.23)
2020-07-17T12:50:57.7258731Z mercurial (4.4.1)
2020-07-17T12:50:57.7259442Z paramiko (1.16.0)
2020-07-17T12:50:57.7260158Z pip (8.1.1)
2020-07-17T12:50:57.7260864Z pyasn1 (0.1.9)
2020-07-17T12:50:57.7261625Z pycrypto (2.6.1)
2020-07-17T12:50:57.7262364Z Pygments (2.1)
2020-07-17T12:50:57.7263653Z PyYAML (3.11)
2020-07-17T12:50:57.7264117Z setuptools (20.7.0)
2020-07-17T12:50:57.7264553Z six (1.10.0)
So as you see there is no azure.functions.

Azure Python SDK for Blobs - ImportError: cannot import name 'BlobClient'

I'm writing code to download a Blob from Azure but I can't import BlobClient.
from azure.storage.blob import BlobClient
cs = "CONNECTION_STRING"
blob = BlobClient.from_connection_string(cs, container="mycontainer", blob="config.ini")
with open("./config.ini", "wb") as my_blob:
blob_data = blob.download_blob()
my_blob.writelines(blob_data.content_as_bytes())
I keep getting the error that follows:
$ python3 download.py
Traceback (most recent call last):
File "download.py", line 1, in <module>
from azure.storage.blob import BlobClient
ImportError: cannot import name 'BlobClient'
I'm using Virtual Env:
pip3 install pylint
python3 -m venv env
pip3 install -r requirements.txt
My requirements.txt file looks like this:
Flask
azure-storage-blob
My Python version is:
$python3 -V
Python 3.6.8
I was using stable version whereas the BlobClient only exists in pre-release.
This solved my problem:
pip3 install azure-storage-blob --pre

No module named 'requests' when pip installing ssh-import-id

I'm using Heroku as a development server. When I try to push my Django application to Heroku it first tries to install my packages from the requirements.txt file.
requests==2.18.3
ssh-import-id==5.5
The problem is I have a dependency on one of my packages with others. In the above packages, ssh-import-id needs requests package already installed. So when I push the app, pip fails to install and stops the deployment.
Collecting requests==2.18.3 (from -r re.txt (line 1))
Using cached https://files.pythonhosted.org/packages/ba/92/c35ed010e8f96781f08dfa6d9a6a19445a175a9304aceedece77cd48b68f/requests-2.18.3-py2.py3-none-any.whl
Collecting ssh-import-id==5.5 (from -r re.txt (line 2))
Using cached https://files.pythonhosted.org/packages/66/cc/0a8662a2d2a781db546944f3820b9a3a1a664a47c000577b7fb4db2dfbf8/ssh-import-id-5.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-go0a5mxf/ssh-import-id/setup.py", line 20, in <module>
from ssh_import_id import __version__
File "/tmp/pip-install-go0a5mxf/ssh-import-id/ssh_import_id/__init__.py", line 25, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-go0a5mxf/ssh-import-id/
I need to install all the listed packages using pip in single attempt. Because by default Heroku runs, pip install -r requirements.txt.
This is a bug.
The library's setup.py imports the library to get the version for inclusion in the setup() function call...
import os
from setuptools import setup
from ssh_import_id import __version__
... and the library tries to import requests which doesn't yet exist in the environment. This is ssh_import_id.__init__.py:
import argparse
import json
import logging
import os
import platform
import requests # <=== here
import stat
import subprocess
import sys
import tempfile
A fix has been added which works around needing to import the package to get the version...
import os
from setuptools import setup
import sys
def read_version():
# shove 'version' into the path so we can import it without going through
# ssh_import_id which has deps that wont be available at setup.py time.
# specifically, from 'ssh_import_id import version'
# will fail due to requests not available.
verdir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "ssh_import_id"))
sys.path.insert(0, verdir)
import version
return version.VERSION
... but the fix isn't in the current pypi version 5.6.
You could install latest master branch from source instead of pypi by changing your requirements.txt to something like:
-e git+https://git.launchpad.net/ssh-import-id#egg=master

Python import google.oauth2.credentials ImportError: No module named google.oauth2.credentials

i'm trying to run this bot https://github.com/ItsCEED/Youtube-Comment-Bot
in mac os but i get this error
l:Youtube-Comment-Bot-master ROOTXX$ python yt.py
Traceback (most recent call last):
File "yt.py", line 6, in <module>
import google.oauth2.credentials
ImportError: No module named google.oauth2.credentials
l:Youtube-Comment-Bot-master ROOTXX$
Run in a root terminal:
pip install --upgrade google-api-python-client
From here, found with a google search.
EDIT: Even better, you linked the required libraries yourself. They are in the GitHub README.md at here. Please read your own links. Anyway, the commands to install follow:
# pip install --upgrade google-api-python-client
# pip install --upgrade requests
# pip install --upgrade beautifulsoup4

Python 2.7 Bloomberg blpapi import error on Mac OS X Sierra

After successful installation of the pybgg, when tried to run
$python test_pybbg.py
Got the following error message:
ImportError: No module named blpapi
MacBook:pfinance Allen$ which python
/Users/Allen/anaconda/bin/python
MacBook:pfinance Allen$ python test_pybbg.py
Traceback (most recent call last):
File "test_pybbg.py", line 2, in
import pybbg
File "/Users/Allen/anaconda/lib/python2.7/site-packages/pybbg/init.py", line 8, in
from .pybbg_k import Pybbg
File "/Users/Allen/anaconda/lib/python2.7/site-packages/pybbg/pybbg_k.py", line 8, in
import blpapi
ImportError: No module named blpapi
I used $pip list, but failed to see blpapi from the output list.
Any suggestions on how to fix my problem?
Thanks in advance
Ps. The followings show my installation log
MacBook:pfinance Allen$ pip install git+https://github.com/hubertrogers/pybbg
Collecting git+https://github.com/hubertrogers/pybbg
Cloning https://github.com/hubertrogers/pybbg to /private/var/folders/c6/7s88m85x0fj7l0zc52y_kcbh0000gn/T/pip-XagRDz-build
Installing collected packages: pybbg
Running setup.py install for pybbg ... done
Successfully installed pybbg-0.0.1
Based on the post I have set the library links properly;
MacBook:pfinance Allen$ echo $DYLD_LIBRARY_PATH
/Users/Allen/pfinance/blpapi_cpp_3.8.1.1/Darwin/
MacBook:pfinance Allen$ echo $BLPAPI_ROOT
/Users/Allen/pfinance/blpapi_cpp_3.8.1.1

Categories