6

I am working on a python project and I am sadly experienced that once I attempt to run the script from the PyCharm ide I get the following error message:

from .cv2 import *
ImportError: libavcodec.so.57: cannot open shared object file: No such file or directory

Now running the same python script from terminal runs without any error so I feel pretty confident that every requirement is installed properly. Therefore I turned my attention to environment variables but I am not completely sure what should the name and value be of the variable I am supposed to add to pycharm environment variable list. I run the following command:

whereis libavcodec.so.57

and I got:

libavcodec.so: /usr/lib/x86_64-linux-gnu/libavcodec.so.57 /usr/lib/x86_64-linux-gnu/libavcodec.so

So I guess that has something to do with the the value of the env variable I am supposed to add to PyCharm.

Can anybody help me how to solve this?

DalekSupreme
  • 1,493
  • 3
  • 19
  • 32

2 Answers2

2

This is because of the way you install the openCV.

Try the following command to install openCV correctly:

$ sudo apt-get remove python-opencv; sudo apt-get install python-opencv
pheeleeppoo
  • 1,491
  • 6
  • 25
  • 29
Pedram
  • 53
  • 6
0

I found my ubuntu 19.10 system has libavcodec.so.58 and not libavcodec.so.57. I had a similar issue with package digiKam.

I solved it, crudely, in terminal window going to the folder containing libavcodec.so, by using:

sudo ln -s libavcodec.so.58.35.100 libavcodec.so.57

(I also had to do similar step with libavutils.so)

I realize this symbolic link will not be updated during system upgrades and is not an ideal solution. The version numbers may also be different on your system.

When I checked into PyCharm Community Edition, I noticed it is invoked using a .sh script. Using a Terminal Window would execute .bashrc each time and it may contain export LD_LIBRARY_PATH=/usr/local/my_lib:$LD_LIBRARY_PATH. That may explain some of the differences with your python import behaviour. I could not reproduce your exact problem with package opencv-python.

Sildeag
  • 74
  • 9