Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "ImportError: libXrender.so.1: cannot open shared object file" when importing OpenCV

I'm having trouble importing OpenCV.

Environment:

  • Python 3.6.1
  • Linux (HPC server)
  • OpenCV 3.4.3.18

Error Description:

I'm trying to import cv2 after a successful installation (Requirement already satisfied: opencv-python in /home/users/czxu/.local/lib/python3.6/site-packages (3.4.3.18)) with command: import cv2, but it seems that a folder or script is missing:

Traceback (most recent call last):
  File "scripts/preprocessing/gen_mini_batches.py", line 4, in <module>
    from avod.builders.dataset_builder import DatasetBuilder
  File "/home/users/czxu/avod/avod/builders/dataset_builder.py", line 6, in <module>
    from avod.datasets.kitti.kitti_dataset import KittiDataset
  File "/home/users/czxu/avod/avod/datasets/kitti/kitti_dataset.py", line 11, in <module>
    from wavedata.wavedata.tools.core import calib_utils
  File "/home/users/czxu/avod/wavedata/wavedata/tools/core/calib_utils.py", line 3, in <module>
    import cv2
  File "/home/users/czxu/.local/lib/python3.6/site-packages/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: libXrender.so.1: cannot open shared object file: No such file or directory
srun: error: sh-06-20: task 0: Exited with exit code 1

I went to the folder /home/users/czxu/.local/lib/python3.6/site-packages/cv2/

czxu@cv2$cd /home/users/czxu/.local/lib/python3.6/site-packages/cv2
czxu@cv2$ls -a
.  ..  cv2.cpython-36m-x86_64-linux-gnu.so  data  __init__.py  .libs  LICENSE-3RD-PARTY.txt  LICENSE.txt  __pycache__

Do you have any idea about this? Answers and discussions will be sincerely appreciated.

like image 798
Xu Chengzhe Avatar asked Sep 28 '18 03:09

Xu Chengzhe


2 Answers

Had the same problem (Python 3.6.6, opencv 3.4.3.18, Ubuntu 18.04). I fixed it by installing libXrender:

sudo apt-get install libxrender1

This was documented here. After installing, I am able to import cv2.

like image 138
Card Crusher Avatar answered Nov 20 '22 23:11

Card Crusher


yum -y install libSM-1.2.2-2.el7.x86_64 --setopt=protected_multilib=false
yum -y install libXext-1.3.3-3.el7.x86_64 --setopt=protected_multilib=false
like image 1
rainy guan Avatar answered Nov 20 '22 21:11

rainy guan