Cannot find module cv2 - Python Jupyter Notebook

Options
FSeifeldin
FSeifeldin Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 2 Partner

Hi,

I am trying to run a python script on a Jupyter Notebook that requires using OpenCV. I installed OpenCV in my code environment and it shows in the installed packages, but every time I try to run the import cv2 line in my Jupyter notebook on Dataiku, it gives me this error:

cv2 error dss.PNG

Even though it shows in the installed packages in the code environment as shown below:OPENCV.PNG

I also checked the notebook's kernel and it uses the correct code environment. I have also built the code environment for my container configuration.

I appreciate your support to help me figure out how to fix this issue.

Answers

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,209 Dataiker
    Options

    Hi,

    Can you try to unload your kernel and try starting it again? Or simply switch your notebook to another kernel and back to the one with cv2 installed and let us know if you are still seeing the same issue.

    When you update a code environment and your notebook kernel is already loaded it will fail to detect new packages installed in the code env.

    Thanks,

  • FSeifeldin
    FSeifeldin Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 2 Partner
    Options

    Thanks Alex for your help. I did as you said, and my code notebook ran successfully without any errors. However, when I created a code recipe from the notebook and ran the recipe, it gave me the same error even though it runs perfectly in the notebook. recipe error.PNG

    I checked that the recipe is using the same code environment. I even tried to change the code env for the recipe then change it back again to the correct one and run the recipe, but it still gives me the same error. I also did not change anything in the code env, so I am not sure why this is happening.

    Thanks again for your help!

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,209 Dataiker
    Options

    Can you confirm if spicy is installed in your code env?

    Perhaps some of the packages were removed and code env still loaded by the notebook still has those packages.

    Are you using local execution or containerized execution for your recipe?

    Can you try using local execution after checking that spicy is in Packages to install and updating the code env:

    Screenshot 2022-02-08 at 15.12.22.png

    If the issue persists you may want to open a support ticket with the job diagnostics and code env diagnostics for us to review further.

  • tgb417
    tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,595 Neuron
    Options

    @FSeifeldin

    I’ve had similar problems. Between notebooks and recipes. In my case it is often that I need to go into the advanced tab on the recipe and select a code environment as well.

    This knowledge base post shows the three main places I know of to control which code environment you are using. https://knowledge.dataiku.com/latest/courses/advanced-code/work-environment/code-env.html

Setup Info
    Tags
      Help me…