ImportError: cannot import name 'enums' - python

I am trying to use Google Speech API to recognize speech from mic input in real time. I have tried https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/transcribe_streaming_mic.py
but this error came out. Anybody knows how to solve this?
from google.cloud.speech import enums
ImportError: cannot import name 'enums'
Update:
I have solved the problem by running the code in virtual environment as suggested by the official Cloud Speech API website. However, I still dont understand why we need to run that in virtual environment instead of my original environment as the virtual environment is not Linux or other OS.

I am using cloud function to transcribe the audio to text.
I believe the documentation for google-cloud-speech has been updated, you may refer to the documentation. https://pypi.org/project/google-cloud-speech/. I believe the class is now called speech_v1, you can use the alias "as speech" to make the github sample codes work.
from google.cloud import speech_v1 as speech
from google.cloud.speech_v1 import enums
from google.cloud.speech_v1 import types
HTH.

I got mine working with the following import
from google.cloud.speech_v1.gapic import enums

Using pip install google.cloud.speech, you are getting the latest version, currently V2.
In V2, enums and types have been removed and are no longer needed.
https://github.com/googleapis/python-speech/blob/master/UPGRADING.md#enums-and-types

Related

Can't access Aliexpress functions in top.api

I'm just started to search Aliexpress-API documentation. In there: Developers.aliexpress , Im coding in python and need to import AliexpressSolutionProductPostRequest from top.api but it fails.
I installed top lib on Windows like that: python -m pip install top
Reinstalled twice but it fails. Its official website and fails. I can't figure it out.
AttributeError: module 'top.api' has no attribute 'AliexpressSolutionProductPostRequest'
This library has diffrent functions for Alibaba , not for aliexpres. Any suggestion for fix that ? Actually i can't find top library's offical documentation too.Thank you..
Okey. I found this library for fix that error. We need to install aliexpress-sdk:
pip install aliexpress-sdk
or (for pre-release):
pip install git+https://github.com/bayborodin/aliexpress-sdk
Now I can import Aliexpress modules which are in Aliexpress API Documentation.
Example module import for aliexpress:
from aliexpress.api import AliexpressSolutionProductPostRequest
I just learned offical way to do that.
After create an app on Aliexpress Console, you can generate API SDK for Python. In there you can find top library's functions which are in Aliexpress API Documentation. So we need to create App first, once accepted , we can do all these stuff.

Erwin API with Python

I am trying to get clear concept on how to get the Erwin generated DDL objects with python ? I am aware Erwin API needs to be used. What i am looking if what Python Module and what API needs to used and how to use them ? I would be thankful for some example !
Here is a start:
import win32com.client
ERwin = win32com.client.Dispatch("erwin9.SCAPI")
I haven't been able to browse the scapi dll so what I know is from trial and error. Erwin publishes VB code that works, but it is not straightforward to convert.
Install pywin32 (run the below from pip folder e.g. c:\Program Files\Python37\Scripts)
python -m pip install pywin32
python pywin32_postinstall.py -install
Sample script to extract DDL using Erwin's Forward Engineer functionality (change paths accordingly):
import win32com.client
api = win32com.client.Dispatch("erwin9.SCAPI")
unit = api.PersistenceUnits.Add("c:/models/data_model.erwin", "RDO=Yes")
unit.FEModel_DDL("c:/scripts/ddl_script.sql")
For the above to work, Erwin application should be running (probably).

How do I import a Google Module directly in AWS Lambda?

I am trying to process an audio file from my S3 through a Lambda function which should call the google speech api to to speech-to-text with the file. However, it doesn't seem like Lambda has this module installed.
Is there a way to import the module externally/manually?
import json
import boto3
import array as arr
import botocore
from botocore.vendored import requests
import os
import urllib
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
def lambda_handler(event, context):
output = 'test'
return output
Expected is that the import works, however the error output is the following:
"errorMessage": "Unable to import module 'lambda_function': No module
named 'google'",
You have to add the google library to your deployment package. Depending on your deployment process, there's various ways how to go about it. The documentation is a good place to start learning about that.
BTW, instead of Google's speech-to-text you can use the one from AWS called Transcribe. You don't have to install any additional library to use that, boto3 will do.
Check the python version used for installing the dependencies and give the same runtime in aws Lambda. I used python 3.8 for installing and gave 3.7 in runtime and ran into this error.
A better way would be to create a file called requirements.txt and add all the dependencies in there
google-cloud-speech==0.36.0
On my understanding, this problem could be solved by adding the required modules as a Layer in Lambda. Then it will be available to your script.
Also, that Layer could be re-used for other Lambdas in the future.

How can I access to library " plot_utils " in python?

I need this library "plot_utils" for analysis and plotting but I can't find it in the web. this library is related to Brian2 (a library in python) for spiking neural network.
I installed brian2 through anaconda. when I want to import plot_utils and using in my code I receive error :
ModuleNotFoundError: No module named 'plot_utils'
Could you please help me?
You need to give more info about where did you stumble upon that name, eg some copied code etc.
With the only reference you've given (ie. brian2) this seems related.
https://brian2.readthedocs.io/en/stable/examples/frompapers.Stimberg_et_al_2018.plot_utils.html
Maybe just copy that code into a file named 'plot_utils.py' and keep it at the path your code is searching for it.
First, you need to install the module in your work environment using "pip install plot_utils" then you can import the library using "import plot_utils".
This link will help you: https://libraries.io/pypi/plot-utils[this is the official documentation from plot_utils]

Problems Using CEX API in Python-- Cannot use module.

I am currently attempting to use the cex.io Python API for accessing financial data. Here is a link to github with the library: https://github.com/matveyco/cex.io-api-python
I installed it on MacOS X by using "python setup.py install" in Terminal. In the link above, it says to initialize the class we should use the following:
import cexapi
api = cexapi.api(username, api_key, api_secret)
However, when I put this code in a .py file in a directory without any other files, bash responds with:
AttributeError: 'module' object has no attribute 'api'
I am pretty sure the library is correctly installed (Python has no problem importing cexapi). It is clear to me that there is something about Python objects that I don't understand or I must have incorrectly installed the module.
Just in case it helps, I ran the following in the Python interpreter:
import cexapi
cexapi.__file__
And got the following:
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/cexapi-0.1-py3.4.egg/cexapi/__init__.py'
This command should show where the module is stored. Any help would be greatly appreciated, as I need to use this API. Thanks.
use upper case letters:
import cexapi
api = cexapi.API(username, api_key, api_secret)

Categories