-1

I tried on python3 terminal ;

    pi@raspberrypi:~ $ python3
    Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import cv2
    >>> 

It seems nothing wrong But i want to run my py file

pi@raspberrypi:~ $ sudo python /home/pi/berber/ornek.py 
Traceback (most recent call last):
  File "/home/pi/berber/ornek.py", line 1, in <module>
    import cv2
ImportError: No module named cv2

Terminal says you dont have cv2. But if i dont have cv2 python3 command cant import cv2. How can i fix this problem

omerklbkr
  • 17
  • 3

1 Answers1

0

Your first example demonstrates that your normal (non-root) user's Python3 environment has OpenCV installed.

Your second example demonstrates that OpenCV is not installed in the root user's Python environment.

So, you are confusing two different users and potentially two different Python versions. You can work out what you are running when a normal user with:

type python3

Then, unless you have installed OpenCV privately for that user, you should be able to run the same thing under sudo.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432