Home > Blockchain >  Python code not working when virtual environment is active but works when it is deactivated
Python code not working when virtual environment is active but works when it is deactivated

Time:07-18

I am using code that relies on the opencv library, the code is cloned from the following repo if someone wishes to reproduce this problem fully:
https://github.com/kmhmubin/Face-Recognition-Attendance-System
but the exact snippet that I was struggling with is here:

# ----------- train images function ---------------
def TrainImages():
    recognizer = cv2.face_LBPHFaceRecognizer.create()
    # rest of the code...

And this code was giving me a "cv2 attribute not found: face" error when the virtual environment was active but when I deactivated it the code worked properly, why is that exactly? Am I not supposed to run the code when the venv is active or is there something wrong with my venv setup?

For the venv setup I followed the exact same steps in the above repo and tried running the code while it was still active, is this incorrect? I tried to check if this is a version issue but the problem is that when I tried to install the 4.0.1 opencv contrib version to the venv it didn't recognize it as a valid version.

CodePudding user response:

You probably did a "pip install" without activating your virtualenv

CodePudding user response:

When you downloaded the package and created your virtual environment did you install the necessary packages specified on the README.md file?

  • pip install opencv-contrib-python
  • pip install numpy
  • pip install pandas
  • pip install Pillow
  • pip install pytest-shutil
  • pip install python-csv
  • pip install yagmail

Also, keep in mind the README.me file says this package was written in Python 3.7 however, the print() functions in main.py suggests this is Python2 This could have caused an error as well.

  • Related