Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: numpy.core.multiarray failed to import #762

Open
lvilaca16 opened this issue Oct 29, 2024 · 10 comments
Open

ImportError: numpy.core.multiarray failed to import #762

lvilaca16 opened this issue Oct 29, 2024 · 10 comments

Comments

@lvilaca16
Copy link

lvilaca16 commented Oct 29, 2024

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
@changliu98
Copy link

changliu98 commented Oct 29, 2024

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

@xyling2023
Copy link

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!

@changliu98
Copy link

changliu98 commented Oct 30, 2024

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

@xyling2023
Copy link

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

@cqray1990
Copy link

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?

@fgy624
Copy link

fgy624 commented Nov 12, 2024

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

@KejiaZhang-Robust
Copy link

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 

@JCSTARS
Copy link

JCSTARS commented Nov 26, 2024

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!

@Mei0211
Copy link

Mei0211 commented Dec 2, 2024

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

@KejiaZhang-Robust
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants