Answers: <p>Seems to be just an issue with a Python package.</p>
  
  <pre><code>Traceback (most recent call last):
    File "a.py", line 1, in &lt;module&gt;
      import cv2
  ImportError: No module named 'cv2'
  </code></pre>
  
  <p>Is a common Python error, basically it can't find the package cv2.</p>
  
  <p>You could try and install OpenCV through pip instead of installing through apt get.
  Something could be up with dependancies that you may have missed.</p>
  
  <pre><code>RUN pip3 install opencv-python 
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-08-08T10:10:40.057Z
Answers: 2019-08-08T10:10:40.057Z
Answers: Cathal A. Dinneen
Body: <p>I am trying to build a Docker container in Raspbian 10.</p>
  
  <pre><code>FROM python:3.5-buster
  RUN apt-get update
  RUN apt-get install apt-utils -y
  RUN apt-get install python-opencv -y
  RUN apt-get install python3-opencv -y
  COPY a.py /
  CMD ["python3", "a.py"]
  </code></pre>
  
  <p><code>a.py</code> is simply <code>import cv2</code></p>
  
  <p>When I run the container, I got the following errors.</p>
  
  <pre><code>Traceback (most recent call last):
    File "a.py", line 1, in &lt;module&gt;
      import cv2
  ImportError: No module named 'cv2'
  </code></pre>
  
Comments: CC BY-SA 4.0
Comments: 2019-08-07T14:45:16.167Z
Comments: perhaps your python code might help? Also, this may have less to do with DevOps, than raspberry pi - have you tried posting in the rpi SO?
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2019-08-08T03:10:17.543Z
Comments: @BruceBecker My python code has one line: `import cv2`.  I just posted in rpi as you suggested.
Comments: wannik
Tags: <dockerfile>
Title: cannot import OpenCV in a Docker container in Raspberry Pi
UserDisplayName: wannik
ThreadText: # cannot import OpenCV in a Docker container in Raspberry Pi
  
  (Asked by: username_0 on 2019-08-07)
  
  I am trying to build a Docker container in Raspbian 10.
  
  ```
  FROM python:3.5-buster
  RUN apt-get update
  RUN apt-get install apt-utils -y
  RUN apt-get install python-opencv -y
  RUN apt-get install python3-opencv -y
  COPY a.py /
  CMD ["python3", "a.py"]
  
  ```
  
  `a.py` is simply `import cv2`
  
  When I run the container, I got the following errors.
  
  ```
  Traceback (most recent call last):
    File "a.py", line 1, in <module>
      import cv2
  ImportError: No module named 'cv2'
  
  ```
  
  **Tags:** dockerfile
  
  > **Comments:**
  > **username_1**: perhaps your python code might help? Also, this may have less to do with DevOps, than raspberry pi - have you tried posting in the rpi SO?  
  > **username_0**: @username_1 My python code has one line: `import cv2`.  I just posted in rpi as you suggested.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-08-08. Score: 1
  
  Seems to be just an issue with a Python package.
  
  ```
  Traceback (most recent call last):
    File "a.py", line 1, in <module>
      import cv2
  ImportError: No module named 'cv2'
  
  ```
  
  Is a common Python error, basically it can't find the package cv2.
  
  You could try and install OpenCV through pip instead of installing through apt get.
  Something could be up with dependancies that you may have missed.
  
  ```
  RUN pip3 install opencv-python 
  
  ```
  
  
  ---
  
  