2

I am getting this error RuntimeError: Numpy is not available, while trying to run the following line of code:

img = torch.from_numpy(np.array(pic, mode_to_nptype.get(pic.mode, np.uint8), copy=True))

Is there a way to solve this without the need to change python version?

Note: my python version is 3.10.

4
  • 1
    This topic seems to be about the same issue, yet it hasn't got any good answer stackoverflow.com/questions/71689095/… Commented Jul 13, 2022 at 10:40
  • Is there a way to downgrade the python version without re-installing it all over again? Because I am afraid if I uninstall python all my installed packages will be removed and I will re-install many of them again. Commented Jul 13, 2022 at 10:50
  • 2
    please use anaconda to manage these package error; trust me its the best Commented Jul 13, 2022 at 11:00
  • Thanks, it was fixed with anaconda, maybe because anaconda uses python 3.9 instead of 3.10 Commented Jul 13, 2022 at 21:31

2 Answers 2

1

Although, this is an old question.

We are still getting this warning for numpy 2.0.

So, the solution as of August 14th 2024 be:

pip install numpy==1.26.4
Sign up to request clarification or add additional context in comments.

1 Comment

pip install "numpy<2" =))) I like this solution more, as your comment in stackoverflow.com/questions/71689095/…
0

Just had the same problem running torchvision with python3.12; torch docs recommend using a version between Python 3.8 - 3.11.

Solution

Create a new environment running on python3.9, I'm using MacOS with Homebrew so command is:

python3.9 -m venv /path/to/your/new/virtual/environment

Once this environment was created I installed torchvision with a specific numpy version lower than 2.0.0

# Install lower version of numpy to avoid compatibility issues.
pip install numpy==1.24.1
pip install torch torchvision

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.