How can I import ObjectId from the bson package into Apache Beam pipeline (that is compatible with pymongo)? - pymongo

Hi I'm working on a pipeline in google Dataflow that loads some MongoDB documents (with pymongo) and process it. At some point I need to cast an id to a MongoDB ObjectId.
To cast it I use the bson package, the problem is that with the dataflowRunner is not detecting the package, and I don't understand why because I declared pymongo[srv] in setup.py.
If I declare bson in the setup.py I get an error because the installed bson dependency is not compatible with pymongo.
I know that pymongo comes with its own bson package but how can I make it available inside an Apache Beam pipeline?

Related

Google Speech API cannot import name 'enums'

I am trying to use Google Speech API to recognize speech, on windows with colab
here is the error
ImportError: cannot import name 'enums' from 'google.cloud.speech_v1'
Anybody knows how to solve this?
Looks like in the new version they have removed enums. Check this link, If you want enums then you have to switch to an old version.
As mentioned in #addno1's answer, enums and types have been removed in the 2.x versions of the library. It seems that you are using a 2.x version of the library, hence the error.
If your code is using the 1.x version of the library and if you would like to upgrade to the latest version of the library, refer to this migration guide(same mentioned in the other answer). You can refer to this quick start for setup instructions and an updated client library code given below.
# Imports the Google Cloud client library
from google.cloud import speech
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
gcs_uri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"
audio = speech.RecognitionAudio(uri=gcs_uri)
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code="en-US",
)
# Detects speech in the audio file
response = client.recognize(config=config, audio=audio)
for result in response.results:
print("Transcript: {}".format(result.alternatives[0].transcript))
If you want to use the older code, you will have to downgrade the library version to 1.3.2 (last 1.x version) by running the pip command
pip install google-cloud-speech==1.3.2

Installed gurobi , not refelecting when importing

I have installed gurobi, however it does not get reflected when importing.
I get the following error:
No module name gurobi
You didn't write which API you are using. If you are using python, you should use import gurobipy and not gurobi. You also need to setup some environment variables (GUROBI_HOME, PATH and LD_LIBRARY_PATH). See Gurobi quick start guide.

module 'tensorflow' has no attribute 'logging'

I'm trying to run a tensorflow code in v2.0 and I'mg getting the following error
AttributeError: module 'tensorflow' has no attribute 'logging'
I don't want to simply remove it from the code.
why this code has been removed?
why should I do instead?
tf.logging was for Logging and Summary Operations and in TF 2.0 it has been removed in favor of the open-source absl-py, and to make the main tf.* namespace has functions that will be used more often.
In TF.2 lesser used functions are gone or moved into sub-packages like tf.math
So instead of tf.logging you could:
tf_upgrade_v2 will upgrade script and changes tf.logging to tf.compat.v1.logging
Python logging module can be used instead
Import absl-py library
If you are using someone else's code it's better to install same Tensorflow version as the author used, or downgrade your Tensorflow version. You may wanna try this:
pip install tensorflow==1.15.0
Or if you have gpu:
pip install tensorflow-gpu==1.15.0
You may still get depricated warnings, however you don't need to modify several files replacing tf with tf.compat.v1

google-cloud-speech speech.types.RecognitionConfig

I am current running on Debian 8 Jessie with Python 2.7 and the current google-cloud-speech and storage (pip'd in with upgrade today). When I attempt to config it fails with:
ValueError: Protocol message RecognitionConfig has no "enable_automatic_punctuation" field.
from this call:
config = speech.types.RecognitionConfig(
encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=8000,
language_code='en-US',
# Enable automatic punctuation
enable_automatic_punctuation=True)
The call was directly copy/paste'd from "https://cloud.google.com/speech-to-text/docs/automatic-punctuation#speech-enhanced-model-python".
Huh?
enable_automatic_punctuation is only available if you import speech_v1p1beta1 instead of speech_v1. Compare the documentation for RecognitionConfig for both beta and non beta.
Also, in the very same example that you have linked, if you click on View on Github, you can see the following import:
from google.cloud import speech_v1p1beta1 as speech
Also, related to this topic.
EDIT:
Also, that code is on Python 3, and you are using Python 2.7, be aware of that.

warning in xml.tree in openpyxl

I am using openpyxl from different Python version using following way.
sys.path.insert(0,
'/remote/Python-2.7.2-shared/linux32/lib/python2.7/site-packages/openpyxl-1.6.1-py2.7.egg')
sys.path.insert(1,
'/remote/Python-2.7.2-shared/linux32/lib/python2.7/site-packages')
I will not receive any warning when I directly use particular version.
Python-2.7.2-shared/linux32/lib/python2.7/site-packages/openpyxl-1.6.1-py2.7.egg/openpyxl/shared/compat/elementtree.py:30:
UserWarning: Unable to import 'xml.etree.cElementree'. Falling back on
'xml.etree.Elementree'
I am reading more than 100 xlsx File and did manual testing previously and need to provide quick fix.
As per my understanding, I am reading xlsx File and does not contain any xml element.
So it should not impact any reading data in xlsx File. can be confirm it or can I ignore this warning.
One small thing not related to openpyxl.
is it possible to hide this warning. I do not have root permission
You can ignore warnings. What you are doing is not recommended. The warning is just that without cElementTree your code may run slow. Python does support install packages for in user home directories but using virtual environments (virtualenv) is preferable.