SOS - ModuleNotFoundError: No module named 'cv2' - tried everything!

Hi there! I am trying to deploy my streamlit app and have tried what feels like a million different ways to find cv2. I’m using an environment.yml to import my dependencies and have tried removing many of them, adding opencv-python-headless, using a requirements.txt (see the text_requirements.txt in the repo below), changing versions, updating all to the newest versions, you name it… no luck!

I would really really appreciate any help the Streamlit crew can provide. I am worried the import is failing on a different package but I cannot see that in the logs. Hoping to get this demo up and running ASAP for a capstone project.

Here’s the repo.

Please let me know if there is anything I can do! Thank you!!

Just to be clear, the naming of this file isn’t optional, it must be requirements.txt if you want Streamlit Cloud to use this to install on pip.

You also have an environment.yml file…you should use one or the other, specifying all of your dependencies in a single file.

Additionally, there are no GPUs on Streamlit Cloud, so I suspect this line will give you issues:

Best,
Randy

I created two “requirements” type files - one with pip and one with conda. I named this one something else so that streamlit would not use it but I didn’t have to delete or move it. I would like streamlit to use my environment.yml

1 Like

I am not actually using any GPU capabilities, I set device to CPU however I think I need cuda to install the detectron2 library. Should I assume that I will be unable to deploy my app with Streamlit Cloud if this is this case?

Also thank you Randy for responding so promptly! I hope you’re having a good week

@jr7777

see my pull request on github.
Installation on streamlit cloud works now, but be aware, you have to choose Python 3.9 during deployment. However, the model execution itself still fails, but this is beyond my knowledge of this specific detectron2 ML library.
Also, there were a lot of path related bugs in your demo, which i had to fix.
Did this demo app ever worked before on a local system?

Thank you for working on this Franky!

I’ll take a look at the detectron2 issues, I’m hoping it’s because I don’t have the model weights in the repo at the moment. Yes, this has been running for a while on my local system which is surprising given how many issues you fixed! Will keep posted on if I can get this thing off the ground

I also think the remaining issues are due to the fact, that in these config yml files, there are still paths pointing to files on your local windows machine with the model weights?

1 Like

Yes I think so. Do you know of any way I can point to the model weights without having to upload them to the github repo? For example paths to google drives or something like that. I’m worried they will be too big to have in the repo (around 260 MB). Can I zip them maybe? and unpack in the code…

I’ll give this a shot but if you have any ideas or experience in this I’d love to hear. You saved my day!

I have no experience with it, but it could theoretically go with Google Drive.
How big are the individual files with the weights? As long as the individual files are smaller than 100MB, there should be no problems and you won’t need Git-LFS.
Should… :wink:

I have not tried Git-LFS with Streamlit Cloud yet. But there have been posts here with reports that it doesn’t work, but no guarantee that this information is true, there is so much going on with Streamlit.
But I would rather not bet on this horse.
Or just give it a try with Git-LFS…

Loading model managed by Git LFS

Unfortunately each is around 130, 200 or 260MB :smiling_face_with_tear: … good to know about Git LFS issues! I’ll give that a quick try and if no luck, onto the next :smile:

As you suggested, you could also try compressing the files and unpacking them when you start the application. But this could also be a bit tricky.
Would it be possible to compress the files enough to get them below 100MB? Or are they already compressed?

I’ve been trying with LFS but apparently it doesn’t work for a forked repository! So I’m stuck there for now.

The files are .pth extensions. I think I could compress them maybe?

Ok, good to know.
If this is the only limitation, you could remove the .git folder and commit a fresh new git(hub) repo?
Of course, you will loose the link to the original repo…

Edit:
Btw, if you make a new github repo, i would refactor the whole demo app:

  • put the streamlit app and requirements.txt in the root folder
  • remove everything from the original repo, that you don’t need. I think you don’t need most of this stuff.
  • add only those folders/files that are required by your demo app

This demo is part of another project so I think the goal is to keep them all together but I will chat with the team and you’re right, if it’s the only bottle neck, having a new git repo might be the easiest solution! Will definitely reformat in that case :yum: thanks again for all your help!!

I have tried git-lfs in a test project and it seems to work with streamlit cloud. I intentionally put a large file > 100MB in github and then created a streamlit app to read in that file and it worked. However, i didn’t test the limits.

Awesome! Thank you. I got my repository deforked and trying lfs now :blush:

1 Like

I have finally uploaded the models, seem to have fixed path issues etc… BUT now I have the app crashing without error logs: [manager] Streamlit server consistently failed status checks when I try to run the model.

I’ve been reading up and people suggested changes to the config file, I upgraded my streamlit to have 3GB of resources but it’s still crashing. Wondering if you could suggest anything? Not sure how to improve the memory usage of the app. Tried caching but caused other errors…

Btw, I’m working in a copy of the repo now: repo

Hm, as I said, I didn’t test the limits.
I will have a look.
But probably someone from the streamlit staff could help better.

1 Like