0

Not sure if this is more google-cloud-related or pytest-related. See files below.

When I run either python app/my_script.py or python -m app.my_script, the script runs fine.

But when I run pytest, the line in the script from google.cloud import vision throws "ModuleNotFoundError: No module named 'google.cloud'".

I have tried unsuccessfully to add various package names into the requirements.txt file and/or run pip install google-cloud and pip install google-cloud-language with and without --upgrade flags. What steps can I take to overcome this error?


conftest.py: (empty)

requirements.txt:

google-cloud-vision

app/my_script.py:

from google.cloud import vision
from google.cloud.vision import types

def new_client():
    client = vision.ImageAnnotatorClient()
    return client

if __name__ == "__main__":
    client = new_client()
    # etc...

test/test_my_script.py:

from app.my_script import new_client

# tests here... 
s2t2
  • 2,462
  • 5
  • 37
  • 47
  • 1
    Are you using a virtual environment and is pytest installed inside of it? – Klaus D. May 14 '19 at 04:17
  • using an anaconda env `conda create -n my-env python=3.7` which has subsequently been activated. turns out pytest wasn't installed in the environment (and was maybe running from somewhere else), but then I did `pip install pytest` and the result is the same. – s2t2 May 14 '19 at 05:52
  • hmm it is possible that a fresh environment and `pip install --upgrade pip` may have solved the issue. – s2t2 May 14 '19 at 06:18

0 Answers0