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 for cv2 dependencies in a virtualenv #95

Closed
TuneBot opened this issue Jun 16, 2017 · 4 comments
Closed

ImportError for cv2 dependencies in a virtualenv #95

TuneBot opened this issue Jun 16, 2017 · 4 comments

Comments

@TuneBot
Copy link

TuneBot commented Jun 16, 2017

Context

In Windows 7 (x64) with C:\Users\user1>C:\Python27\python.exe C:\VirtualenvTools\virtualenv.py --python=C:\VirtualenvTools\Python36\Python.exe C:\virtualenvs\virtualenv I create a virtualenv and set its C:\virtualenvs\virtualenvname\Scripts\Python.exe file as the main interpreter for a PyDev project in Eclipse.

I also installed lackey after entering the virtualenv with activate as well with the command pip install lackey @ the C:\virtualenvs\virtualenvname\Scripts\ directory without any listed errors.

The problem

When I import lackey with from lackey import * in my project, there is an ImportError from Eclipse's console.

The console's stackTrace:
Traceback (most recent call last):
File "C:\Users\user1\workspace\sikulixframework0.1\testManager.py", line 4, in <module>
from lackey import *
File "C:\virtualenvs\virtualenvname\lib\site-packages\lackey\__init__.py", line 31, in <module>
from .RegionMatching import Pattern, Region, Match, Screen, ObserveEvent
File "C:\virtualenvs\virtualenvname\lib\site-packages\lackey\RegionMatching.py", line 17, in <module>
import cv2
File "C:\virtualenvs\virtualenvname\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: DLL load failed: Le module spécifié est introuvable.

(Le module spécifié est introuvable. = The specified module could not be found.)

When using the same interpreter (C:\virtualenvs\virtualenvname\Scripts\Python.exe) directly, if I write from lackey import * I get the same stackTrace

My resolution tries

I tried the same things (from lackey import *) outside a virtual environment and it worked. Like suggested in an answer to the stackoverflow's question 'Can't import cv2; “DLL load failed”' I downloaded the Visual C++ 2015 redistributable package but nothing of my complications changed.

@TuneBot
Copy link
Author

TuneBot commented Jun 16, 2017

I created a stackoverflow question (my first one!) because this problem looks like a more general one (problem with virtualenv? DLL problem?) even if it may be only lackey.

https://stackoverflow.com/questions/44593975/importerror-for-cv2-with-lackey-in-a-virtualenv

@glitchassassin
Copy link
Owner

Someone reported a similar issue on the opencv-python repository. The specific case they cited was an Anaconda install, but other limited installs of Python might be affected as well.

Can you confirm that you have python3.dll (or appropriate version) somewhere in your path?

@TuneBot
Copy link
Author

TuneBot commented Jun 16, 2017

I added in the Windows PATH environment variable, the path to the original Python3.6.1 from the path\to\original\python36\python.exe in C:\Users\user1>C:\Python27\python.exe C:\VirtualenvTools\virtualenv.py --python=C:\VirtualenvTools\Python36\Python.exe C:\virtualenvs\virtualenv command for the virtualenv creation that contained that python3.dll file and added that same python3.dll file in the C:\virtualenvs\virtualenv\Scripts directory and it worked!

Summary if you use virtualenv

  1. Make sure the path to the executable (which contains the python3.dll file in python3.6.1 at least) referenced by the virtualenv (after that --python= part of the creation command) is in the "PATH" Windows environment variable.
  2. Add that same python3.dll file to the \Scripts\ directory where the virtualenv is.

Wow!!!
I did not think that a virtualenv was using the Windows path variables. Thanks for the hints.

@glitchassassin
Copy link
Owner

Looks like this is actually also an issue in virtualenv.

@TuneBot TuneBot changed the title Lackey and it's cv2 dependency in a virtualenv ImportError for cv2 dependencies in a virtualenv Jun 16, 2017
@TuneBot TuneBot closed this as completed Jun 16, 2017
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