When I run my script that uses torch I get the following error:
File "C:\Users\USER\AppData\Local\Programs\Python\Python312\Lib\site-packages\torchvision\transforms\functional.py", line 168, in to_tensor
img = torch.from_numpy(np.array(pic, mode_to_nptype.get(pic.mode, np.uint8), copy=True))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Numpy is not available
I just freshly installed numpy and torch today using pip. What could be the issue?
Ok after tracking the error log I found:
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Apparently numpy released a new version (numpy 2.0.0) just two day ago (2024/06/17) and pip by default installs the new version which is not compatible with pytorch yet as I assume.
Downgrading numpy to the last stable version of numpy v1 using the following command fixed the issue:
pip install numpy==1.26.4