Sunday, 23 October 2022

ImportError from google.cloud when calling a script from a fastapi server

I am trying to get a fastapi server to use the documentai sdk from google.cloud

I run everything in a conda env on my local machine.

When I run the documentai script on its own, it works fine. The fastapi server also works.

However, when I import

from google.cloud import documentai

in my fastapi script, I get

ImportError: cannot import name 'documentai' from 'google.cloud' (unknown location)

No matter how I call that script (either as a module, putting the code directly in the server, or using os.system('python documentai_script.py')), I get the same error.

To install the module, I used a conda environment. Inside of that environment, I did

'''pip install --upgrade google-cloud-documentai'''

Once in the environment, I can do

'''python documentai_script.py''' successfully

And

'''main.py''' if the documentai module is not present in my server, main.py

If there is any reference of or mention of google.cloud in main.py, I get the above error.

Hope this is clear!



from ImportError from google.cloud when calling a script from a fastapi server

No comments:

Post a Comment