Why ehy i am gettin this error PLEASE PLEASE HELP

i dont know why i am getting this error i have installed every thing but still please help please

here’s the error

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import cv2
  File "/home/runner/Python-Beta-LSP-1/venv/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
  File "/home/runner/Python-Beta-LSP-1/venv/lib/python3.10/site-packages/cv2/__init__.py", line 111, in bootstrap
    load_first_config(['config.py'], True)
  File "/home/runner/Python-Beta-LSP-1/venv/lib/python3.10/site-packages/cv2/__init__.py", line 109, in load_first_config
    raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.

my code

import cv2

def remove_background(image_path):
    # Load the image
    image = cv2.imread(image_path)

    # Convert the image to grayscale
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # Apply a threshold to create a binary image
    _, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

    # Find contours in the binary image
    contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    # Create a mask with the same shape as the image
    mask = np.zeros_like(image)

    # Draw the contours on the mask
    cv2.drawContours(mask, contours, -1, (255, 255, 255), thickness=cv2.FILLED)

    # Apply the mask to the image
    result = cv2.bitwise_and(image, mask)

    # Return the result
    return result

# Example usage
image_path = "Removebg.jpg"
result = remove_background(image_path)
cv2.imshow("Result", result)

thanks i will try i was stucked in it thanks bro

no bro again :frowning:

Hey @mygyasir!

Thank you for reporting this. I will look into this issue and will let you once I have an update.

Hey! We have an internal team looking at this. Keep an eye out here for more updates.

Hello @mygyasir, I’ve figured out a way to unblock the error you are seeing, however I have not yet managed to run opencv-python with the Qt GUI tools: I am still investigating that.

If you need to only use the non-GUI functionality, you can do the following to get around the config file error:

  1. Create a pip.conf file containing:
user = yes
  1. in .replit, within the [env] section, add the line: PIP_CONFIG_FILE = "$REPL_HOME/pip.conf"
  2. re-install the opencv-python library:
pip uninstall opencv-python
pip install opencv-python

Running a program using non-GUI operation should work. See main.py and main1.py.

Or, you can fork from this opencv-python template which I’ve created.

Wouldn’t pip install --force-reinstall opencv-python work for that?

well that is true, @tobyho’s answer is intuitive while your’s would be more efficient.

Either way is fine as long as it works :slight_smile: