google-coral / tflite

Examples using TensorFlow Lite API to run inference on Coral devices
https://coral.withgoogle.com
Apache License 2.0
182 stars 67 forks source link

ModuleNotFoundError: No module named 'tflite_runtime' #14

Closed cburgdorfer closed 4 years ago

cburgdorfer commented 4 years ago

After following the instructions on https://coral.ai/docs/accelerator/get-started/#on-mac, I get the following error on macOS 10.15, python 3.7.3:

$ python3 classify_image.py --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --labels models/inat_bird_labels.txt --input images/parrot.jpg
Traceback (most recent call last):
  File "classify_image.py", line 36, in <module>
    import tflite_runtime.interpreter as tflite
ModuleNotFoundError: No module named 'tflite_runtime'

Does anybody have an idea what the issue could be and how it can be fixed?

Namburger commented 4 years ago

Do you know where the tflite_runtime package was installed? It may just not be presented in your python path. Please show me the outputs of this command:

$ python3 -m pip show --verbose tflite-runtime

And

$ python3 -c 'print(__import__("sys").path)'
cburgdorfer commented 4 years ago

Thanks for your quick response, and your offer to help! Much appreciated! The first command outputs nothing, the second provides a bunch of paths.

$ python3 -m pip show --verbose tflite-runtime
$ python3 -c 'print(__import__("sys").path)'
['', '/Users/cburgdorfer/miniconda3/lib/python37.zip', '/Users/cburgdorfer/miniconda3/lib/python3.7', '/Users/cburgdorfer/miniconda3/lib/python3.7/lib-dynload', '/Users/cburgdorfer/miniconda3/lib/python3.7/site-packages']
$ 
Namburger commented 4 years ago

@cburgdorfer Sorry, was in a meeting. First command outputs nothing either means that you don't have it installed or you have multiple python version installed and only 1 of it knows? For macOS with python3.7.3, you should be using this:

$ python3 -m pip install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-macosx_10_14_x86_64.whl

Can you try that again, take notes of the outputs to make sure we know where it's installed?

cburgdorfer commented 4 years ago

Thanks again, @Namburger , I have found out what the problem was thanks to your comment:

The documentation says I should run the pip install ... command, but thanks to your comment, I've found out, I need to call python3 -m pip install ...

This was the output accordingly:

$ python3 -m pip install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-macosx_10_14_x86_64.whl
Collecting tflite-runtime==2.1.0.post1 from https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-macosx_10_14_x86_64.whl
  Using cached https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-macosx_10_14_x86_64.whl
Requirement already satisfied: numpy>=1.12.1 in /Users/cburgdorfer/miniconda3/lib/python3.7/site-packages (from tflite-runtime==2.1.0.post1) (1.16.4)
Installing collected packages: tflite-runtime
Successfully installed tflite-runtime-2.1.0.post1

Thanks again! Much appreciated!

Namburger commented 4 years ago

Ahh I see confusion, your pip is most likely pip2 and not pip3, so then when your python3 try to load the package, it couldn't find it lol

Edit: To clarify,

$ python3 -m pip install ...

is the same as

$ pip install

But only if your default pip is pip3. if you have pip2 as default, when you do a pip install, it's equivalent to:

$ python2 -m pip install ...

In general, we document pip install because that's what people used to. But for me explicit is always better and more "secure" so I go with python3 -m pip install.