LAVIS icon indicating copy to clipboard operation
LAVIS copied to clipboard

ImportError: numpy.core.multiarray failed to import

Open lvilaca16 opened this issue 1 year ago • 10 comments

I am currently using salesforce-lavis to use BLIP-2. I am getting errors regarding incompatibilities between numpy and opencv. Despite multiple warnings, I updated both packages and it worked, thus I am listing this issue for registration purposes.

Current environment:

name: blip2
channels:
  - defaults
dependencies:
  - python=3.11
  - pip
  - pip:
    - salesforce-lavis

It installs the following versions:

  • opencv-python: 4.5.5.64
  • numpy: 2.0.2

Error traceback:

RuntimeError: module compiled against ABI version 0x1000009 but this version of numpy is 0x2000000                                     
Traceback (most recent call last):                                                                                                     
 File "/nas-ctm01/homes/luismsalgado/deep_av_dial/scripts/run_blip2.py", line 4, in <module>                                          
   from lavis.models import load_model_and_preprocess                                                                                 
 File "/nas-ctm01/homes/luismsalgado/.conda/envs/blip2/lib/python3.10/site-packages/lavis/__init__.py", line 15, in <module>          
   from lavis.datasets.builders import *                                                                                              
 File "/nas-ctm01/homes/luismsalgado/.conda/envs/blip2/lib/python3.10/site-packages/lavis/datasets/builders/__init__.py", line 8, in <
module>                                                                                                                                
   from lavis.datasets.builders.base_dataset_builder import load_dataset_config                                                       
 File "/nas-ctm01/homes/luismsalgado/.conda/envs/blip2/lib/python3.10/site-packages/lavis/datasets/builders/base_dataset_builder.py", 
line 18, in <module>                                                                                                                   
   from lavis.processors.base_processor import BaseProcessor                                                                     
 File "/nas-ctm01/homes/luismsalgado/.conda/envs/blip2/lib/python3.10/site-packages/lavis/processors/__init__.py", line 10, in <module
>
   from lavis.processors.alpro_processors import (
 File "/nas-ctm01/homes/luismsalgado/.conda/envs/blip2/lib/python3.10/site-packages/lavis/processors/alpro_processors.py", line 13, in
<module>
   from lavis.processors.randaugment import VideoRandomAugment
 File "/nas-ctm01/homes/luismsalgado/.conda/envs/blip2/lib/python3.10/site-packages/lavis/processors/randaugment.py", line 8, in <modu
le>
   import cv2
 File "/nas-ctm01/homes/luismsalgado/.conda/envs/blip2/lib/python3.10/site-packages/cv2/__init__.py", line 8, in <module>
   from .cv2 import *
ImportError: numpy.core.multiarray failed to import

My solution:

pip install -I -U numpy
pip install -I -U opencv

lvilaca16 avatar Oct 29 '24 10:10 lvilaca16

Sams issue with Python 3.9.20 and numpy 2.0.2. I solved it by use Conda to create a Python 3.11 env with pip installed numpy 2.1.2, pip installed salesforce-lavis==1.0.2 and conda installed opencv, which should be 4.10.0 without specifying version number UPDATE when run models still got runtime error due to numpy or opencv

changliu98 avatar Oct 29 '24 22:10 changliu98

Sams issue with Python 3.9.20 and numpy 2.0.2. I solved it by use Conda to create a Python 3.11 env with pip installed numpy 2.1.2, pip installed salesforce-lavis==1.0.2 and conda installed opencv, which should be 4.10.0 without specifying version number

I encountered the same issue. Following your method for installation:

conda create -n lavis python=3.11
conda activate lavis
pip install numpy==2.1.2
pip install salesforce-lavis==1.0.2
conda install opencv

Then, using from lavis.models import model_zoo raises an error indicating that some packages are missing. I installed the following packages: pip install torchaudio moviepy peft easydict diffusers

However, when I continue using from lavis.models import model_zoo, I still get the error:

RuntimeError: Failed to import diffusers.models.autoencoders.autoencoder_kl because of the following error (look up to see its traceback):
Failed to import diffusers.schedulers.scheduling_dpmsolver_multistep because of the following error (look up to see its traceback):
maximum recursion depth exceeded

Have you encountered such a problem? Thank you for your help!

xyling2023 avatar Oct 30 '24 01:10 xyling2023

Only installs, but sill have runtime error When you run ``` pip install salesforce-lavis==1.0.2 ``` pip will uninstall numpy then install `numpy 2.0.2` for you, just run `pip install numpy==2.1.2` and install 2.1.2 ignoring the dependency error, I tested on my machine and it works (though i think the they need to update the dependencies). My steps is listed here: ``` conda create -n lavis python=3.11 conda activate lavis pip install salesforce-lavis==1.0.2 pip install numpy==2.1.2 conda install opencv ``` and ``` Python 3.11.10 (main, Oct 3 2024, 07:29:13) [GCC 11.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from lavis.models import model_zoo /home/hello/anaconda3/envs/lavis/lib/python3.11/site-packages/fairscale/experimental/nn/offload.py:19: FutureWarning: `torch.cuda.amp.custom_fwd(args...)` is deprecated. Please use `torch.amp.custom_fwd(args..., device_type='cuda')` instead. return torch.cuda.amp.custom_fwd(orig_func) # type: ignore /home/hello/anaconda3/envs/lavis/lib/python3.11/site-packages/fairscale/experimental/nn/offload.py:30: FutureWarning: `torch.cuda.amp.custom_bwd(args...)` is deprecated. Please use `torch.amp.custom_bwd(args..., device_type='cuda')` instead. return torch.cuda.amp.custom_bwd(orig_func) # type: ignore >>> ```
When generates output still outputs runtime error due to incompatible numpy ver

changliu98 avatar Oct 30 '24 02:10 changliu98

Only installs, but sill have runtime error When generates output still outputs runtime error due to incompatible numpy ver

To resolve version compatibility issues between diffusers and huggingface_hub, as well as between numpy and lavis, I applied the following fixes, and now the demo runs successfully:

pip install diffusers==0.16.0
pip install huggingface_hub==0.24.6
pip install spacy==3.6.0
pip install numpy==1.24.0

xyling2023 avatar Oct 30 '24 05:10 xyling2023

Only installs, but sill have runtime error When generates output still outputs runtime error due to incompatible numpy ver

To resolve version compatibility issues between diffusers and huggingface_hub, as well as between numpy and lavis, I applied the following fixes, and now the demo runs successfully:

pip install diffusers==0.16.0
pip install huggingface_hub==0.24.6
pip install spacy==3.6.0
pip install numpy==1.24.0

where mode zoo models can be downloaded?

cqray1990 avatar Nov 11 '24 07:11 cqray1990

You can try to install opencv-python! I solve this problem by doing this pip install opencv-python

fgy624 avatar Nov 12 '24 01:11 fgy624

You can try the following steps to set up your environment:

conda create -n lavis python=3.11 -y  
conda activate lavis  
pip install --upgrade pip  
pip install salesforce-lavis  
pip install opencv-python 

KejiaZhang-Robust avatar Nov 18 '24 08:11 KejiaZhang-Robust

You can try the following steps to set up your environment:

conda create -n lavis python=3.11 -y  
conda activate lavis  
pip install --upgrade pip  
pip install salesforce-lavis  
pip install opencv-python 

Thanks a lot! I've faced the same problem, and it really works!

JCSTARS avatar Nov 26 '24 12:11 JCSTARS

This question has also been troubling me for a long time. The final solution is to follow the latest version of OpenCV Python, as it supports numpy>2.0 pip install opencv-python=4.10.0.84

Mei0211 avatar Dec 02 '24 04:12 Mei0211

This question has also been troubling me for a long time. The final solution is to follow the latest version of OpenCV Python, as it supports numpy>2.0 pip install opencv-python=4.10.0.84

Maybe it’s a good practice to clear the pip cache to avoid potential conflicts by running before setup a new environmental.

pip cache purge

KejiaZhang-Robust avatar Dec 02 '24 05:12 KejiaZhang-Robust