google-coral / pycoral

Python API for ML inferencing and transfer-learning on Coral devices
https://coral.ai
Apache License 2.0
347 stars 144 forks source link

ModuleNotFoundError: No module named 'pycoral.pybind' (am64, Windows 10, python 3.9) #51

Closed CaptainPineapple closed 2 years ago

CaptainPineapple commented 2 years ago

Description

What i am trying to do and why

I am currently trying to integrate a dual edge tpu into our system. The problem i face is that due to other packages we are using i am bound to specific versions of python and numpy (python 3.9 and numpy 1.19.3) Now i was very delighted to find out that pycoral is already available prebuild for 3.9 but the prebuild wheel does not work with the numpy version i need. So i tried building the wheel myself from the source provided in the repos releases.

To set up my system I followed the official coralai setup for windows as described here in the getting started documentation The runtime installer reports success on completion.

To build the wheel i downloaded the source and ran python -m build in the folder. Output does not indicate any errors.

The error

Building the wheel in general finishes successfully and i can install the wheel on my system. However i face the following issue when running the following code:

from pycoral.utils.edgetpu import make_interpreter

Error:

....
  File ".....\lib\site-packages\pycoral\utils\edgetpu.py", line 24, in <module>
    from pycoral.pybind._pywrap_coral import GetRuntimeVersion as get_runtime_version
ModuleNotFoundError: No module named 'pycoral.pybind'

I am aware that this issue in some form was already brought up in #48, #32 well as #24 but no suggestion in said threads did solve the issue for me.

some basic analysis of my system

The path explorer does indeed not show a module named pybind as child of pycoral and as can be seen on the right side the source pycoral folder does not contain this as well. Is this correct and i am missing something here? image

Please let me know if any more information is required or if you have any hints as to what i could do to further analyse this issue.

Thanks in advance,

Click to expand! ### Issue Type Build/Install ### Operating System Windows 10 ### Coral Device M.2 Accelerator with dual Edge TPU ### Other Devices _No response_ ### Programming Language Python 3.9 ### Relevant Log Output _No response_
hjonnala commented 2 years ago

Can you please share the build log details and the generated wheel.

CaptainPineapple commented 2 years ago

thx for your fast reply. sorry for not adding this in the first place.

pycoral-2.0.0-py3-none-any.zip build log.txt

hjonnala commented 2 years ago

can you first try to install pycoral on virtual env and test if the M.2 edge tpu working or not..later, you can work on building pycoral with numpy1.19.3.

for edgetpu runtime installation please check this comment: https://github.com/google-coral/libedgetpu/issues/29#issuecomment-909207700

Thanks!

CaptainPineapple commented 2 years ago

well the issue is: i have to use tensorflow 2.5 which is only compatible with numpy=~1.19.2 (which should be okay for pycoral as it only states as dependency: numpy>=1.16.0)

So i can try to set this up for you if this is helpful for you but i do not see how this will help me solve my issue down the road if i test the hardware now in some completly different environment. If i remove my selfbuilt package and install the official one (while using numpy==1.19.3 which as already posted should be alright) i get the following error on from pycoral.utils.edgetpu import make_interpreter :

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\itom (x64)\python3\lib\site-packages\pycoral\utils\edgetpu.py", line 24, in <module>
    from pycoral.pybind._pywrap_coral import GetRuntimeVersion as get_runtime_version
SystemError: initialization of _pywrap_coral raised unreported exception

Which is basically what i was trying to work around as i thought that this was not supported. I just earlier realized that this version should in general be working to start with. Sadly I was not able to find any meaningful solutions/information to this error.

i also rolled back to runtime version 13 as described in your last post but got the same result.

i attached the success install log of pycoral from the official repo here: install_log_pycoral2.0.txt

hjonnala commented 2 years ago

Hi, some users are facing issues in detecting m2 dual edge tpu with their hardwares. So, I just first wanna make sure hardware is working properly.

In regards to pycoral, it has dependency with tflite runtime. Can you try to build tflite-runtime==2.5.0.post1 with numpy 1.19.3 using this commit and then build the pycoral.

hjonnala commented 2 years ago

You can also try this example first which can be run with just tflite runtime.

CaptainPineapple commented 2 years ago

sorry to keep you waiting. Was out of town for the last 2 days and building the tflite-runtime proves difficult as i do not have fitting linux machine at hand. Will let you know when i managed to follow your suggested path..

CaptainPineapple commented 2 years ago

I am still not able to compile the runtime as suggested. My linux machine does not have the capacities to build for windows using bazel and on windows i constantly run into issues that still did not manage to resolve. Is there anything else i could try?

EDIT: Finally after idontknowhowmanyhours bazel reports success. Apparently there still is an issue with python building the wheel from the bazel output. Will report back once i find the log and what's going wrong...

CaptainPineapple commented 2 years ago

Back to square one. I succeeded in building the runtime wheel, removed old runtime + pycoral packages, installed the new runtime. Then built the pycoral2.0 package as in my first post and came to the exact same result EDIT: attached the wheels below for reference. The build output for pycoral has not changed. wheels.zip .

hjonnala commented 2 years ago

Hi, I am able to run this example with the provided tflite_runtime whl after adding (metrics_interface.py and metrics_portable.py) from tflite_runtime2.5.0 post1 installation package.

Can you please share the build script used for pycoral?

CaptainPineapple commented 2 years ago

well your post made me realize that my build of pycoral was probably not correct. As i wrote in my first post:

To build the wheel i downloaded the source and ran python -m build in the folder. Output does not indicate any errors.

i guess i just figured out that this is not the right way to do it? Only issue beeing: running scripts\windows\build.bat just leads to more issues:

cmd.exe /S /E:ON /V:ON /D /c rc.exe /nologo /fo bazel-out\x64_windows-opt\bin\src\edgetpu.res bazel-out\x64_windows-opt\bin\src\edgetpu.rc Execution platform: @local_execution_config_platform//:platform 'rc.exe' is not recognized as an internal or external command, operable program or batch file. Target //src:edgetpu.res failed to build

EDIT: do you have any clues regarding the error above? i am not that familiar with building with bazel and cannot really figure out why rc.exe is not found as it clearly is on PATH and can be accessed from any command line - also running in elevated privileges. Can you also explain what you mean by

after adding (metrics_interface.py and metrics_portable.py) from tflite_runtime2.5.0 post1 installation package.

Where to add those?

hjonnala commented 2 years ago

after adding (metrics_interface.py and metrics_portable.py) from tflite_runtime2.5.0 post1 installation package.

Where to add those?

please add metrics_interface.py and metrics_portable.py to ../Lib/site-packages/tflite_runtime

I am not getting rc.exe error. But, I have a different error

Can you try this: rc.exe bazel-out\x64_windows-opt\bin\src\edgetpu.rc

CaptainPineapple commented 2 years ago

Can you try this: rc.exe bazel-out\x64_windows-opt\bin\src\edgetpu.rc

ran this and got the following output:

F:\.....\pycoral>rc.exe bazel-out\x64_windows-opt\bin\src\edgetpu.rc Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384 Copyright (C) Microsoft Corporation. All rights reserved.

hjonnala commented 2 years ago

can you please check bazel-out\x64_windows-opt\bin\src\edgetpu_rc.res copy to pycoral/src/. And try the demo after deleting line 56 to 65 from src/BUILD file.

CaptainPineapple commented 2 years ago

will try to follow your suggestion next but for the moment: The build succeeded. i was able to run build.bat and build_wheel.bat at last after copying the script files as by your suggestion. So the resulting wheel is here:

pycoral-2.0.0-cp39-cp39-win_amd64.zip

I installed this wheel by this command: python -m pip install --no-deps pycoral-2.0.0-cp39-cp39-win_amd64.whl (no-deps if using my own build tflite-runtime package. i tested both same result) Problem is now:

from pycoral.utils.edgetpu import make_interpreter

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    from pycoral.utils.edgetpu import make_interpreter
ModuleNotFoundError: No module named 'pycoral'

while python correctly reports:

F:\....\pycoral\dist>python3 -m pip install pycoral-2.0.0-cp39-cp39-win_amd64.whl
Processing f:\.....\pycoral\dist\pycoral-2.0.0-cp39-cp39-win_amd64.whl
Requirement already satisfied: numpy>=1.16.0 in f:\......\python\lib\site-packages (from pycoral==2.0.0) (1.19.3)
Requirement already satisfied: tflite-runtime==2.5.0.post1 in f:\......\python\lib\site-packages (from pycoral==2.0.0) (2.5.0.post1)
Requirement already satisfied: Pillow>=4.0.0 in f:\......\python\lib\site-packages (from pycoral==2.0.0) (8.2.0)
Installing collected packages: pycoral
Successfully installed pycoral-2.0.0

this issue is just getting more weird by the minute...

EDIT: formatting & I also checked the python path browser the package is indeed not to be found in there..

EDIT2: inspecting/decompressing the wheel clearly shows that there are no contents beside the dist info in there.

hjonnala commented 2 years ago

have you cloned the pycoral with this command? git clone --recurse-submodules https://github.com/google-coral/pycoral

CaptainPineapple commented 2 years ago

Yes. To be sure i reran git submodules update --init --recursive Output:

$ git submodule update --init --recursive
Submodule path 'libcoral/libedgetpu': checked out '3164995622300286ef2bb14d7fdc2792dae045b7'
Submodule path 'libcoral/test_data': checked out '104342d2d3480b3e66203073dac24f4e2dbb4c41'

I also attached the build_wheel.bat output here: output.txt

First time i missed the warning that build\lib does not exist. Might be the issue here i guess? I just cannot figure out why that is. As bazel reports success i assumed that the necessary files to build the wheel have been created. I have no clue where to even start looking why this might be missing...

CaptainPineapple commented 2 years ago

IT WORKS!!

after doing some research on the warning above i tried running python setup.py bdist_wheel -d ./dist manually from the pycoral base folder. (taken from the build_wheel.bat script) Apparently this is an issue when executing this from a different location as described here

from pycoral.utils.edgetpu import make_interpreter now runs without issues. Thank you so much for your help and patience. You are a lifesaver!

EDIT: Can be closed imo. Let me know if you have any questions if that might be helpful for you in fixing any issues that you might see in the current building scripts.

hjonnala commented 2 years ago

Awesome. Glad to know its working.

google-coral-bot[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No