Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

YOLOv5 Example - No module named 'cv2' #91

Open
vinzbarbuto opened this issue Dec 4, 2023 · 5 comments
Open

YOLOv5 Example - No module named 'cv2' #91

vinzbarbuto opened this issue Dec 4, 2023 · 5 comments

Comments

@vinzbarbuto
Copy link
Collaborator

vinzbarbuto commented Dec 4, 2023

Hello,

I've been working on practicing with Lingua France while attempting to execute the Python YOLOv5 example. I've made sure to install all the required dependencies as suggested, and I've double-checked them. However, when I run the code, I still encounter an error in the terminal: from cv2 import cv2 ModuleNotFoundError: No module named 'cv2'.

I'm wondering if I might be missing something in the library import. Could someone please assist me with this? Any help would be greatly appreciated.

Regards,
Vincenzo

@edwardalee
Copy link
Contributor

When I've run into this, it has been because a different Python is being executed than what I expected.
Assuming you are running the nightly build or GitHub current, then I suggest checking the script that gets put in the bin directory and see whether the Python is what you expect. In my case, I use pyenv to manage Python versions, so what I see in the bin directory is something like this:

#!/bin/sh
/Users/edwardlee/.pyenv/shims/python3.10 /Users/edwardlee/LinguaFranca/test/Python/src-gen/ActionDelay/ActionDelay.py "$@"

@vinzbarbuto
Copy link
Collaborator Author

Thank you, Edward. The issue arose because, even though my Python interpreter in my IDE and my Python version in my terminal were at the same level, a different Python version was introduced into the bin directory after building. I suspect the problem lies with CMake, which is currently configured with that specific Python version. Do you have insights on how I can adjust this configuration to ensure the use of the correct Python version after the Lingua Franca build operation?

Thank you very much,
Vincenzo

@edwardalee
Copy link
Contributor

I'm not sure, but maybe @cmnrd can give us a clue. The PR that introduced the code that generates the shell script (which chooses the Python version) is this one: https://github.com/lf-lang/lingua-franca/pull/1914/files.

This uses a mysterious variable Python_EXECUTABLE for which there is no other mention in the tree, so if I had to guess, I would guess that setting an environment variable with that name might work.

This page on CMake might be helpful: https://cmake.org/cmake/help/latest/module/FindPython.html .

@vinzbarbuto
Copy link
Collaborator Author

Edward, your support is greatly appreciated. Thank you.

@cmnrd
Copy link
Contributor

cmnrd commented Dec 6, 2023

FindPython is unfortunately not very transparent when it comes to why it selects a particular Python interpreter. The "Hints" section provides some insights on how the lookup behavior can be influenced.

I am not sure if these variables can be set as environment variables, or whether they need to be set within cmake (or be passed to it). Perhaps we could expose some of the hints in the target properties, but this might make Python programs less portable.

This uses a mysterious variable Python_EXECUTABLE for which there is no other mention in the tree, so if I had to guess, I would guess that setting an environment variable with that name might work.

Python_EXECUTABLE is set by the call to FindPython. It should not be changed directly (as this would make Python_EXECUTABLE inconsistent with the other variables that FindPython sets).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants