0

I have been using OpenCV for a long time on Jetson Nano. I always started my codes on Jetson Nano terminal with sudo command.

For example:

sudo python3 process.py

When I do:

python3 process.py 

...I can not import opencv. How can I import opencv without using `sudo command on terminal?

Could you please help me?

Jetman
  • 765
  • 4
  • 14
  • 30
  • 1
    How did you install opencv? In a virtual environment? – Yunus Temurlenk Aug 27 '20 at 08:33
  • Yunus' questions is great. Additionally, does the script need to anything `sudo` related ? (e.g. GPIO pins/etc.) ? (Might not, but always worth double checking :) ) – George Profenza Aug 27 '20 at 08:37
  • I installed the OpenCV from this link: github.com/JetsonHacksNano/buildOpenCV. I don't know if it uses virtual environment or not. I use only cv2.imshow command in the script to test my camera. – mücahid barstuğan Aug 27 '20 at 08:45

2 Answers2

0

You need to check sys.path Run python with no sudo:

python3
>>> import sys
>>> print(sys.path)

Then compare output with python which run with sudo:

sudo python3
>>> import sys
>>> print(sys.path)

I think your outputs will be different. Need to make them the same.

Yuriy Zhigulskiy
  • 1,382
  • 9
  • 11
  • The result of python3 import sys print(sys.path) '/home/mucahid/c4aarch64_installer/lib/python37.zip', '/home/mucahid/c4aarch64_installer/lib/python3.7', '/home/mucahid/c4aarch64_installer/lib/python3.7/lib-dynload', '/home/mucahid/c4aarch64_installer/lib/python3.7/site-packages' – mücahid barstuğan Aug 27 '20 at 10:44
  • The result of sudo python3 import sys print(sys.path) '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/mucahid/.local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/dist-packages', '/usr/local/lib/python3.6/dist-packages/Jetson.GPIO-2.0.8-py3.6.egg', '/usr/lib/python3/dist-packages', '/usr/lib/python3.6/dist-packages'] I am not used to Linux system still, so I don't know what to do. – mücahid barstuğan Aug 27 '20 at 10:44
0

Are you by any chance using conda environment?

If so, the python packages installed (system-wide) by the OpenCV build script won't be available in your virtual environment. To solve this, create a symbolic link from your system python site-packages to conda environment site-packages.

Usually it will be like this, (for cv2 specifically) -

ln -s /usr/local/lib/python3.6/site-packages/cv2/python3.6/cv2.cpython-36m-aarch64-linux-gnu.so /home/mucahid/c4aarch64_installer/lib/python3.7/site-packages/cv2.so
Dharman
  • 30,962
  • 25
  • 85
  • 135
vman
  • 163
  • 2
  • 11
  • Thanks for your reply. I solved the problem. When you install Python API for ZED Camera there is a step: To install it run : python3 -m pip install pyzed-3.1-cp37-cp37m-linux_x86_64.whl I changed it as sudo python3 -m pip install pyzed-3.1-cp37-cp37m-linux_x86_64.whl and it worked. Now I can get images from python script by sudo python3 process.py command on the terminal. – mücahid barstuğan Aug 28 '20 at 05:50