Import cv2 error: Symbol not found: _av_buffer_default_free - python

I'm getting this weird runtime (I think) error with cv2 (assumingly) and cannnot resolve it.
i'm using python3.7 on mac:
(proj) user#user-MacBook-Pro:~/Desktop/proj/controllers$ python
Experiments/n_Experiment.py
pybullet build time: Dec 10 2021 09:53:34
Traceback (most recent call last):
File "Experiments/n_Experiment.py", line 1, in <module>
from experiment import Experiment
File "/Users/user/Desktop/proj/ontrollers/experiment.py", line 1, in <module>
from simulation import LinkServer as SimServer
File "/Users/user/Desktop/proj/controllers/pybulletsim/simulation.py", line 11, in <module>
import cv2
ImportError: dlopen(/Users/user/opt/anaconda3/envs/proj/lib/python3.7/site- packages/cv2.cpython-37m-darwin.so, 2): Symbol not found: _av_buffer_default_free
Referenced from: /Users/user/opt/anaconda3/envs/proj/lib/libavformat.58.dylib
Expected in: /Users/user/opt/anaconda3/envs/proj/lib/libavcodec.58.dylib
in /Users/user/opt/anaconda3/envs/proj/lib/libavformat.58.dylib
So far, I've tried to update conda, and all of the following actions which did not help:
update conda navigtors
symbolyc link
ln -s libavformat.58.dylib
reinstall opencv in various ways (using conda, pip3, brew (also tried to brew build from source).
reinstall numpy (there might be a connection apparently).
Any ideas how to resolve it??
Thanks!

Related

CuPy CUDA - Failed to Import CuPy

I have installed the correct version of CuPy with pip install cupy-cuda117 on pyCharms as my CUDA is version 11.7. My Python version is 3.8. I also have the environment variables set but I am still receiving this message:
Traceback (most recent call last):
File "C:\Users\Dominic\PycharmProjects\Project_Trading\venv\lib\site-packages\cupy\__init__.py", line 18, in <module>
from cupy import _core # NOQA
File "C:\Users\Dominic\PycharmProjects\Project_Trading\venv\lib\site-packages\cupy\_core\__init__.py", line 1, in <module>
from cupy._core import core # NOQA
File "cupy\_core\core.pyx", line 1, in init cupy._core.core
File "C:\Users\Dominic\PycharmProjects\Project_Trading\venv\lib\site-packages\cupy\cuda\__init__.py", line 8, in <module>
from cupy.cuda import compiler # NOQA
File "C:\Users\Dominic\PycharmProjects\Project_Trading\venv\lib\site-packages\cupy\cuda\compiler.py", line 13, in <module>
from cupy.cuda import device
File "cupy\cuda\device.pyx", line 1, in init cupy.cuda.device
ImportError: DLL load failed while importing runtime: The specified module could not be found.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/Dominic/PycharmProjects/Project_Trading/regression_to_classification.py", line 77, in <module>
import cupy
File "C:\Users\Dominic\PycharmProjects\Project_Trading\venv\lib\site-packages\cupy\__init__.py", line 20, in <module>
raise ImportError(f'''
ImportError:
================================================================
Failed to import CuPy.
If you installed CuPy via wheels (cupy-cudaXXX or cupy-rocm-X-X), make sure that the package matches with the version of CUDA or ROCm installed.
On Linux, you may need to set LD_LIBRARY_PATH environment variable depending on how you installed CUDA/ROCm.
On Windows, try setting CUDA_PATH environment variable.
Check the Installation Guide for details:
https://docs.cupy.dev/en/latest/install.html
Original error:
ImportError: DLL load failed while importing runtime: The specified module could not be found.
================================================================
Process finished with exit code 1
Here is some additional info:
I ran into something similar when trying to install cupy recently. These are the steps that ultimately resulted in the import error:
Try to pip install cupy.
Realize that this is taking too long and/or requires a compiler etc.
Stop the install/build.
Install one of the prebuilt wheels (e.g. pip install cupy-cuda11x).
Notice that the cupy package is somehow installed (probably a remnant from the first stage).
pip uninstall cupy to get rid of the cupy library which shouldn't be there. << This is the stage that causes the problem!
The last step above breaks whichever mappings the wheel installer creates that allow one to import cupy despite installing a package called e.g. cupy-cuda11x.
The solution that worked for me was to remove all cupy* packages and install only the wheel distribution. In the case shown in the question, reinstalling cupy-cuda11x should do the trick.

Issues with onnxruntime on Ubuntu 16.04

I'm trying to run inference on an ONNX model on Ubuntu 16.04 using onnxruntime. But the import statement gives me this error:
>>> import onnxruntime
/opt/conda/lib/python3.6/site-packages/onnxruntime/capi/_pybind_state.py:13: UserWarning: Cannot load onnxruntime.capi. Error: '/opt/conda/lib/python3.6/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-36m-x86_64-linux-gnu.so: cannot enable executable stack as shared object requires: Permission denied'
warnings.warn("Cannot load onnxruntime.capi. Error: '{0}'".format(str(e)))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/conda/lib/python3.6/site-packages/onnxruntime/__init__.py", line 12, in <module>
from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device, set_seed, RunOptions, SessionOptions, set_default_logger_severity, NodeArg, ModelMetadata, GraphOptimizationLevel, ExecutionMode, OrtDevice, SessionIOBinding
ImportError: cannot import name 'get_all_providers'
After searching online, I have tried using execstack -c on the .so mentioned in the warning. But I get this message and the issue still persists:
section file offsets not monotonically increasing
I would really appreciate some pointers to fix this.
P.S. I even tried installing onnxruntime-gpu (I have CUDA 10.0) but I get the same error.
Not sure if you've SELinux installed? https://ceisoftware.zendesk.com/hc/en-us/articles/202370087-Cannot-enable-executable-stack-as-shared-object-requires-Permission-denied. This doesn't seem to

from .cv2 import * ImportError: DLL load failed: The specified module could not be found

I used to play with opencv but now I am not able to use it. When I enter :
import cv 2
I get
import cv2
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import cv2
File "C:\Program Files\Python36-32\lib\site-packages\cv2\__init__.py", line 3, in <module>
from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
I have 32 bit Windows 7 and Python 3.6.
I had an issue that really looked like this one.
I installed OpenCV on an conda envrionement and someone had installed numpy unsing pip on the base environment.
Please check that:
all your installed package come from compatible sources
You don't have the same package installed twice
The only way that I could fix the issue was starting from a fresh environment.
Hope it helps

Unable to import cv2

I tested the following command in python:
import cv2
I put it in the file b.py and run python b.py. But I met with the following error:
Traceback (most recent call last):
File "b.py", line 1, in <module>
import cv2
File "/home/mypath/anaconda2/lib/python2.7/site-packages/cv2/__init__.py", line 9, in <module>
from .cv2 import *
ImportError: libXdmcp.so.6: cannot open shared object file: No such file or directory
What's wrong with this? Thank you all for helping me!
Did you install opencv correctly? Also what OS are you using (e.g. Windows, Linux OS X etc.)
If you're using windows - did you follow these steps?:
http://docs.opencv.org/3.2.0/d5/de5/tutorial_py_setup_in_windows.html
If you are using Fedora install Opencv by typing this command into the terminal:
sudo yum install numpy opencv*
The cause of the problem may be that you haven't installed the dependencies:
Matplotlib
Numpy
Hope this helps!

Stuck on error loading scipy, using Homebrew install, on macOS Sierra

This happens when I try to do:
import scipy.io
Another scipy module, such as scipy.sparse, seems to be OK.
The root error is:
packages/scipy/special/__init__.py", line 636, in <module>
from ._ufuncs import *
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/scipy/special/_ufuncs.so, 2): Symbol not found: ___addtf3
The full stack trace:
Traceback (most recent call last):
File "HistogramClassifier.py", line 3, in <module>
import scipy.io
File "/usr/local/lib/python2.7/site-packages/scipy/io/__init__.py", line 97, in <module>
from .matlab import loadmat, savemat, whosmat, byteordercodes
File "/usr/local/lib/python2.7/site-packages/scipy/io/matlab/__init__.py", line 13, in <module>
from .mio import loadmat, savemat, whosmat
File "/usr/local/lib/python2.7/site-packages/scipy/io/matlab/mio.py", line 12, in <module>
from .miobase import get_matfile_version, docfiller
File "/usr/local/lib/python2.7/site-packages/scipy/io/matlab/miobase.py", line 22, in <module>
from scipy.misc import doccer
File "/usr/local/lib/python2.7/site-packages/scipy/misc/__init__.py", line 51, in <module>
from scipy.special import comb, factorial, factorial2, factorialk
File "/usr/local/lib/python2.7/site-packages/scipy/special/__init__.py", line 636, in <module>
from ._ufuncs import *
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/scipy/special/_ufuncs.so, 2): Symbol not found: ___addtf3
Referenced from: /usr/local/lib/python2.7/site-packages/scipy/special/../.dylibs/libquadmath.0.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /usr/local/lib/python2.7/site-packages/scipy/special/../.dylibs/libquadmath.0.dylib
That's pretty much it. Google returns quite a few hits, but they're either very old, or not the same lib, or things that I've tried. The rest of this post is all the stuff I found/tried so far that didn't work.
Double checking python:
which python
/usr/local/bin/python
ls -l /usr/local/bin/python
lrwxr-xr-x ... /usr/local/bin/python -> ../Cellar/python/2.7.13/bin/python
I'm not currently using virtual env.
I think Homebrew is OK:
brew doctor
Your system is ready to brew.
This is after trying this:
brew update
brew upgrade
I've also tried uninstalling and reinstalling the scipy package, both with brew and with pip.
I've tried various other things, but don't want to mess up a working Homebrew setup.
Older posts that Google brought back talk about "cobra", as far as I know I'm not using that. "which cobra" doesn't return anything.
Other things from Google talk about the order of the library path, but that seemed to be if you were using the built-in python, which I don't don't think is applicable since I believe I'm using Homebrew's version.
Clearly it has something to do with a library, maybe fortran related, but what to type in to fix it... don't know where to start.
Try this: remove /usr/lib/libSystem.B.dylib temporarily and then reinstall scipy.

Categories

Resources