Numpy is not available error

Traceback (most recent call last):                                                           
File "C:\Users\averw\Desktop\repos\vocal-remover\inference.py", line 184, in <module>          
main()
File "C:\Users\averw\Desktop\repos\vocal-remover\inference.py", line 152, in main              y_spec, v_spec = sp.separate(X_spec)                                                           
File "C:\Users\averw\Desktop\repos\vocal-remover\inference.py", line 77, in separate
mask = self._separate(X_mag_pad, roi_size)
File "C:\Users\averw\Desktop\repos\vocal-remover\inference.py", line 42, in _separate          
X_batch = torch.from_numpy(X_batch).to(self.device)                                            
RuntimeError: Numpy is not available

why is this error happening in PyTorch? I have numpy 1.21.2 installed, and I have PyTorch Nightly with CUDA 11.3

1 Like

I cannot reproduce the issue, as the installation automatically also installs numpy:

pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cu113/torch_nightly.html
...
Installing collected packages: torch, numpy, torchvision
Successfully installed numpy-1.22.3 torch-1.12.0.dev20220311+cu113 torchvision-0.13.0.dev20220311+cu113

Manually uninstalling numpy reproduces the error:

python -c "import torch; import numpy as np; print(torch.from_numpy(np.random.randn(1)))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'

but re-installing it fixes the issue again:

pip install numpy
Collecting numpy
  Using cached numpy-1.22.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.8 MB)
Installing collected packages: numpy
Successfully installed numpy-1.22.3

python -c "import torch; import numpy as np; print(torch.from_numpy(np.random.randn(1)))"
tensor([0.2141], dtype=torch.float64)
1 Like

Okay, it seems to be because i am on Python 3.10. According to here, it’s only available through 3.9.

2 Likes

Yup, by using py -3.9 it works. Solved!

Is there any tracking issue regarding Python 3.10 support on Windows? All I could find is Add Python-3.10 support · Issue #66424 · pytorch/pytorch · GitHub.

I don’t think the linked issue is Linux-specific and would assume it’s also tracking Windows support.
In any case, are you seeing any issues using the Python 3.10 binaries?

are you seeing any issues using the Python 3.10 binaries?

@ptrblck Yes (if I’m not missing something). We’re trying to enable testing with Python 3.10 on Linux/macOS/Windows in CI, but it fails only on Windows due to the same error as reported here.

You can see version info in the CI run, but I’m pasting it here for quick access:

pip list
absl-py            1.1.0
atomicwrites       1.4.1
attrs              21.4.0
bert-score         0.3.10
build              0.8.0
certifi            2022.6.15
cffi               1.15.1
cfgv               3.3.1
charset-normalizer 2.1.0
check-manifest     0.48
click              8.1.3
cloudpickle        2.1.0
colorama           0.4.5
commonmark         0.9.1
coverage           6.4.1
cycler             0.11.0
distlib            0.3.4
fast-bss-eval      0.1.4
ffmpeg-python      0.2.0
filelock           3.7.1
fire               0.4.0
fonttools          4.34.4
future             0.18.2
Gammatone          1.0
huggingface-hub    0.6.0
identify           2.5.1
idna               3.3
imageio            2.19.3
iniconfig          1.1.1
jiwer              2.3.0
joblib             1.1.0
jsonschema         4.6.2
kiwisolver         1.4.3
llvmlite           0.38.1
lpips              0.1.4
matplotlib         3.5.2
mir-eval           0.7
mock               4.0.3
monotable          3.1.0
musdb              0.4.0
museval            0.4.0
networkx           2.8.4
nltk               3.7
nodeenv            1.7.0
nose               1.3.7
numba              0.55.2
numpy              1.22.4
packaging          21.3
pandas             1.4.3
pep517             0.12.0
pesq               0.0.4
phmdoctest         1.4.0
Pillow             8.4.0
pip                22.1.2
platformdirs       2.5.2
pluggy             1.0.0
portalocker        2.5.1
pre-commit         2.19.0
psutil             5.9.1
py                 1.11.0
pyaml              21.10.1
pycocotools        2.0.4
pycparser          2.21
pyparsing          3.0.9
pypesq             1.2.4
pyrsistent         0.18.1
pystoi             0.3.3
pytest             6.2.5
pytest-cov         3.0.0
pytest-doctestplus 0.12.0
pytest-timeout     2.1.0
python-dateutil    2.8.2
python-Levenshtein 0.12.2
pytorch-msssim     0.2.1
pytz               2022.1
PyWavelets         1.3.0
pywin32            304
PyYAML             6.0
regex              2022.7.9
requests           2.28.1
resampy            0.3.1
rouge-score        0.0.4
sacrebleu          2.1.0
scikit-image       0.19.3
scikit-learn       1.1.0
scipy              1.8.1
setuptools         58.1.0
simplejson         3.17.6
six                1.16.0
SoundFile          0.10.3.post1
speechmetrics      1.0
SRMRpy             1.0
stempeg            0.2.3
tabulate           0.8.10
termcolor          1.1.0
threadpoolctl      3.1.0
tifffile           2022.5.4
tokenizers         0.12.1
toml               0.10.2
tomli              2.0.1
torch              1.12.0+cpu
torch-complex      0.4.3
torch-fidelity     0.3.0
torchmetrics       0.10.0.dev0  d:\a\metrics\metrics\src
torchvision        0.13.0+cpu
tqdm               4.64.0
transformers       4.20.1
typing_extensions  4.3.0
urllib3            1.26.10
virtualenv         20.15.1

@ptrblck I’m confused about whether it’s supported by PyTorch or not, because, as @averwhy mentioned above, there is a statement about Python 3.10 on Windows in the official instruction page: Start Locally | PyTorch

Currently, PyTorch on Windows only supports Python 3.7-3.9; Python 2.x is not supported.

1 Like

I don’t fully understand the linked issue by skimming through it.
It seems you depend on numpy but fail to build it.
However, in your environment you already have numpy installed so could you explain how the numpy issue is related to PyTorch’s Python 3.10 support?