Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ImportError: No module named cv2 #81

Closed
YukihimeX opened this issue Jan 5, 2020 · 5 comments
Closed

ImportError: No module named cv2 #81

YukihimeX opened this issue Jan 5, 2020 · 5 comments

Comments

@YukihimeX
Copy link

No matter which version of opencv I installed into my canda VirtualEnv (python 3.6 and 3.7) I cannot (for the love of god) make opencv to work.
import cv2 always give me the "No module name cv2" error.
It's like the damn thing is blind as fck and can't seem to find that opencv is already installed into that Virtual Env. I installed both requirements.txt and requirements-test.txt as well, just to be sure, but still same result.
Does anyone have any idea how to go about solving this issue?
Which OpenCV version did you guys have that work properly?

@leblancfg
Copy link
Owner

Hi @YukihimeX! Well that sucks...

My first guess would be to assume that you're running autocrop from your virtual environment, but autocrop is using a different $PYTHONPATH? Did you activate your environment, and double-check you installed autocrop in your env? (I'm assuming yes, but worth double-checking)

I've done the following steps and cannot duplicate your issue:

  1. conda create -n testenv
  2. conda activate testenv
  3. pip install autocrop
  4. cd folder_with_images
  5. autocrop

Works as intended, at least on my Windows box.

Suggested next step:

  1. Confirm autocrop was installed to env and that it is activated
  2. Try using conda run autocrop and post results.

Hopefully that will get us somewhere :)

Note to self: tangentially related to #7.

@YukihimeX
Copy link
Author

YukihimeX commented Jan 6, 2020

@leblancfg Hi, thank you for taking the time to respond to my issue...
I had some luck since the last time I posted the issue here and somehow manage to get OpenCV to work by installing other users packages that is below 4.0 instead of the conda forge or conda...
But now I get this ImportError: attempted relative import with no known parent package error when I run the code.

I created the 3 folders (pics, crop, nofaces) into D:\VirtualEnv\autocrop\autocrop directory and put a few pictures into the pics folder as a test.

And when I run the conda run autocrop it just say there's no images but when I run it again inside the folder that had a few images autocrop\autocrop\pics... the CMD screen just go blank and the little underscore just keep blinking without any result.
Maybe I've go about it the wrong way? If so please let me know.

Here's my step...

  1. Activate Conda Virtual Env
  2. cd /d autocrop directory
  3. run this code autocrop.py autocrop -i pics -o crop -r nofaces -w 512 -H 512

Please take a look at the screenshot and let me know if I did anything wrong.

Autocrop

@leblancfg
Copy link
Owner

OK so, two things here. Running the autocrop.py file directly is not the same as calling autocrop. I think that's why you're getting those weird import errors. When you install autocrop, you're not just getting a file you can then python autocrop.py with.

Typically, CLI tools such as autocrop, or awscli, cookiecutter, pgsql, etc. are meant to be used in any folder on your machine, and need to be found in your PATH. You call then by their name directly in the terminal, e.g. pgsql -U postgres -d northwind will start up that utility, no matter where you are in the filesystem.

Taking a step back, you can go back to that folder and try running

$ autocrop -i pics -o crop -r nofaces -w 512 -h 512

... or am I reading this all wrong, and that's what you trying previously? 😨

@YukihimeX
Copy link
Author

YukihimeX commented Jan 6, 2020

Never-mind, I was just being an airhead... I forgot to put images into the pics folder when I run autocrop...
Thanks for all your help... Really appreciate it.

@leblancfg
Copy link
Owner

Great to hear! :)

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

No branches or pull requests

2 participants