How to deploy Google Cloud NLP with python - google-cloud-automl

I have my model trained using GCP's auto ML system, and am ready to deploy it using Python. In the sample code provided by Google, they are importing several libraries:
import sys
from google.api_core.client_options import ClientOptions
from google.cloud import automl_v1
from google.cloud.automl_v1.proto import service_pb2
And I cannot find where I can get these libraries. Any help would be appreciated!

They are referencing the official Python Client Library for AutoML. You can download and install it by doing:
Mac
pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install google-cloud-automl
Windows
pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install google-cloud-automl

Related

Sklearn installation

I have installed sklearn library using
pip install sklearn
but while importing it it shows there is no any library called sklearn that is it gives import error
and afterwars i checked again installing using same command mentioned above but it says requirement already satisfied.
Why it showing like this?
What may be the solution for it? Here is the problem screenshot while importing
It's in CMD
C:\Users\scann>pip install sklearn
Requirement already satisfied: sklearn in c:\users\scann\appdata\local\programs\python\python310\lib\site-packages (0.0.post1)
C:\Users\scann>pip install -U sklearn
Requirement already satisfied: sklearn in c:\users\scann\appdata\local\programs\python\python310\lib\site-packages (0.0.post1)
I tried many methods for installation using github and using -U
But also i Didn't find any correct solution
As of today (2023-01-09), pip install sklearn is in a "brownout" period, and installing this way will eventually be removed.
The preferred installation method is:
pip install scikit-learn
The reason for deprecation is listed as:
sklearn package on PyPI exists to prevent malicious actors from using the sklearn package, since sklearn (the import name) and scikit-learn (the project name) are sometimes used interchangeably. scikit-learn is the actual package name and should be used with pip.
Further reading:
https://github.com/scikit-learn/sklearn-pypi-package
https://github.com/scikit-learn/scikit-learn/issues/24204

Python modules are not properly loaded fron Jenkins shell

I have configured a conda environment and created python project. I am using Jenkins freestyle job for project testing. Activated a conda env from Jenkins shell and getting modules not found error, already installed all the required modules to this env.
For information testing cases are working properly when executing pytest server/ command from terminal workspace.
Jenkins Shell Command
#!/bin/bash
source /home/user/anaconda3/etc/profile.d/conda.sh
conda activate Unit-Test
pip list
pytest server/
Using pip list command I try to check the modules installed in env from terminal and Jenkins shell and found some of the libraries are missing when checked from Jenkins Shell.
Already checked with deleting the Jenkins Job caching and created new job to check, but issue still persists. Also tried to install the missing libraries again and again but still having the same issue.
Following libraries are missing in Jenkins shell: (Difference)
asttokens
backcall
debugpy
decorator
executing
ipykernel
pickleshare
psutil
pure-eval
Pygments
python-dateutil
I am not using these libraries directly but boto3 uses python-dateutil as support and I am getting the error:
import boto3
from boto3.session import Session
import botocore.session
import botocore.client
from botocore import waiter, xform_name
from botocore.docs.docstring import WaiterDocstring
from botocore.docs.service import ServiceDocumenter
from botocore.docs.bcdoc.restdoc import DocumentStructure
from botocore.compat import OrderedDict
from dateutil.tz import tzlocal
ModuleNotFoundError: No module named 'dateutil'
I did not get any reason for the issue.
Need Help, Please suggest
Why not install all the modules as part of the job run?
pip install -r requirements.txt
Define all requirements in requirements.txt.

Cannot import GLPK in Anaconda

I searched a lot an answer to my problem but wasn't able to find a fix.
I'm running anaconda.
I installed glpk with from conda-forge with the command:
conda install -c conda-forge glpk
The installation worked fine but then in my notebook, I've got an error message when I try to import the module :
ModuleNotFoundError: No module named 'glpk'
I had no problem to install and import other packages.
Any ideas?
Thank you very much in advance
The files installed by
conda install -c conda-forge glpk
can be found at https://anaconda.org/conda-forge/glpk/files. Looking at the archives only the GLPK C library is installed and no Python binding or package.
One of the packages that can call the GLPK library from Python is Pulp (https://anaconda.org/conda-forge/pulp).
I'm conda/windows user. I never could import it directly, but based on this SO answer I could make work a library that consume it (pypsa)
Basically, download the library (is in sourceforge) and add it to windows system path
Hope this help to somebody googling this issue. Bests

How to make cython a requirement for a pip install?

When creating a Python package and uploading it to pypi, it will automatically install the requirements that are put in the setup.py file under install_requires, e.g.
from distutils.core import setup
setup(
name = 'a_package',
packages = ['a_package'],
install_requires=['another_package']
)
When the package has a cython extension (and .pyx files instead of .c/.cpp files), the setup.py file will need to import cython to create an installable extension, e.g.
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
name = 'a_package',
packages = ['a_package'],
install_requires=['another_package'],
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension('the_extension', sources=['a_file.pyx'])]
)
But since Cython is imported before executing the setup part, when trying to install this package through pip from source (rather than from a wheel) downloaded from pypi, it will fail to install due to not being able to import cython, as it has not reached the part with the requirements yet.
I’m wondering what can be done to ensure that a pip install of this package from pypi will install cython before it tries to import it. Adding a requirements.txt with cython does not seem to add automatic-install requirements for files downloaded from pypi.
Now, I realize it’s possible to just pip install cython before pip install thispackage, but I’m wondering if there’s a better fix that would allow to install the package along with cython directly from pypi when it’s not possible to run an additional command (without resorting to uploading the .c. files and ajusting the setup.py file to use them instead of the .pyx).
What you're describing is a "build time dependency", and this is precisely the use case "PEP 518 -- Specifying Minimum Build System Requirements for Python Projects" was created for.
You can specify cython as a build-time dependency by adding a pyproject.toml file like:
[build-system]
requires = ["cython"]
Then when installing your package with a modern version of pip (or another PEP 518 compatible installer), cython will be installed into the build environment before your setup.py script is run.

ImportError: No module named googlemaps

I've installed this package via pip27 on macports. My OS is OSX El Capitan 10.11.6. My python install is 2.7.10.
I'm trying to run an example script that imports googlemaps module, but I keep getting that ImportError. I have a feeling that it's how pip installed it and the reason why python can't find it, but I'm relatively new to pip so I don't know where to start investigating.
I also tried googling for a fix but no dice. Any idea what's happening here?
Here's my code:
import googlemaps # can't import
import argparse
from datetime import datetime
# collect args for lat, long, # of addresses, radius of search
parser = argparse.ArgumentParser(description='Randomize addresses on Google Maps')
parser.add_argument('-lt', '--latitude')
parser.add_argument('-lng', '--longitude')
parser.add_argument('-n', '--count')
parser.add_argument('-r', '--radius')
args = parser.parse_args()
print('Results: ', vars(args))
Error message:
Traceback (most recent call last):
File "randomize_addresses.py", line 1, in <module>
import googlemaps
ImportError: No module named googlemaps
Found a fix. I uninstalled googlemaps via pip and then reinstalled using easy_install. Apparently OSX doesn't like pip.
Looks like you used pre-installed python since you mentioned version 2.7.10 (default version shipped with macOS) which is located at /usr/bin/.
MacPorts installs binaries and libraries under /opt/local. Try to install python via MacPorts and run the program again. Python and pip should both be linked so that packages installed via pip is available to python.
In this case packages installed using pip27 would be available to python27 installed via MacPorts and not /usr/bin/python.
Another way would be to download get-pip.py and install it against /usr/bin/python (pip installation guide).
Note: Make sure you are using python installed via MacPorts. To check this run which python, it should show something like /opt/local/bin/python2.7

Resources