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 #42441

Closed
WestbrookZero opened this issue Aug 3, 2020 · 12 comments
Closed

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

WestbrookZero opened this issue Aug 3, 2020 · 12 comments
Assignees
Labels
module: numpy Related to numpy support, and also numpy compatibility of our operators module: windows Windows support for PyTorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module windows-triaged

Comments

@WestbrookZero
Copy link

WestbrookZero commented Aug 3, 2020

My environment is Win10 , Pytorch:1.15.1、Torchvision:0.6.1、numpy:1.19.1 , when i change Torchvision to 0.2.2. Post 3 , hiddenimports=['numpy.core.dtype_ctypes'] and change numpy to 1.18.5 or 1.16.4 or 1.15.0 still have this error :

Traceback (most recent call last):
File "detect.py", line 3, in
File "d:\installpath\develop\anaconda3-5.1.0\envs\yolov5\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
File "site-packages\torch_init.py", line 136, in
ImportError: numpy.core.multiarray failed to import
[8580] Failed to execute script detect

cc @mruberry @rgommers @peterjc123 @maxluk @nbcsm @guyang3532 @gunandrose4u @smartcat2010 @mszhanyi

@agolynski agolynski added module: windows Windows support for PyTorch module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Aug 3, 2020
@agolynski
Copy link
Contributor

Could you give an example repro?

@mszhanyi
Copy link
Collaborator

mszhanyi commented Aug 6, 2020

@WestbrookZero, could you please ensure your change in spec not reset. (https://stackoverflow.com/questions/49083667/updating-spec-file-for-pyinstaller-gets-reset)

Strictly, It's a pyInstaller issue rather than pytorch issue.

@zhousteven
Copy link

My environment is Win10 , Pytorch:1.6.0+cpu、Torchvision:0.7.0+cpu、numpy:1.19.2,use pyinstaller:4.0 to make an .exe file, have try to change numpy to 1.18.5 or 1.17.5 or 1.15.0 still have this error :
Traceback (most recent call last):
File "vgg.py", line 9, in
File "d:\programdata\anaconda3\envs\vgg\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.dict)
File "site-packages\torch_init_.py", line 189, in
ImportError: numpy.core.multiarray failed to import
[20924] Failed to execute script vgg

@peterjc123
Copy link
Collaborator

peterjc123 commented Oct 22, 2020

@zhousteven @WestbrookZero What if you do just import numpy?

@mszhanyi
Copy link
Collaborator

@zhousteven , could you try the below in your app.sepc
image

@zhousteven
Copy link

@mszhanyi i have try this way, still occuring the same error

@mszhanyi
Copy link
Collaborator

mszhanyi commented Oct 23, 2020

@mszhanyi i have try this way, still occuring the same error

@zhousteven Could you please tailor you project and provide a small demo for us?

@zhousteven
Copy link

@peterjc123 Have tried your idea, when i only import the relate packages, there isn't an error occring, when i use .exe file; the code coped below:
#!/usr/bin/python

-- encoding:utf-8 --

import numpy
import torch
import torch.nn as nn
from torchvision import transforms
from torch.autograd import Variable
from torchvision import models

from PIL import Image
import logging.config
import yaml
import json

but when i use pyinstaller compile contain invoking load model which trained by pytorch,occuring the error.
should i paste my whole repository code?

@zhousteven
Copy link

@mszhanyi @peterjc123@WestbrookZero first, best appreciate yours kindly help and useful idea. after trail and error find that below method solved my error:
before input package commandline, enter "chcp 65001", after that
enter "pyinstaller -F vgg.py"

@volkov-maxim
Copy link

I'd same error and I solved it with change version of numpy.

Result of import torch

$ python
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import torch
** On entry to DGEBAL parameter number 3 had an illegal value
** On entry to DGEHRD parameter number 2 had an illegal value
** On entry to DORGHR DORGQR parameter number 2 had an illegal value
** On entry to DHSEQR parameter number 4 had an illegal value
Traceback (most recent call last):
File "", line 1, in
File "C:\Projects\Aspose\lib\site-packages\torch_init_.py", line 190, in
from torch._C import *
ImportError: numpy.core.multiarray failed to import

Result of import numpy

import numpy
** On entry to DGEBAL parameter number 3 had an illegal value
** On entry to DGEHRD parameter number 2 had an illegal value
** On entry to DORGHR DORGQR parameter number 2 had an illegal value
** On entry to DHSEQR parameter number 4 had an illegal value
Traceback (most recent call last):
File "", line 1, in
File "C:\Projects\Aspose\lib\site-packages\numpy_init_.py", line 305, in
win_os_check()
File "C:\Projects\Aspose\lib\site-packages\numpy_init
.py", line 302, in _win_os_check
raise RuntimeError(msg.format(file)) from None
RuntimeError: The current Numpy installation ('C:\Projects\Aspose\lib\site-packages\numpy\ini
t
.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more in
formation: https://tinyurl.com/y3dm3h86

Solution:
pip uninstall numpy
pip install numpy==1.19.3

Hope this help.

@rgommers
Copy link
Collaborator

The PyInstaller team is developing some hooks for NumPy to make sure all dll's are packaged, see numpy/numpy#17184. Without it I think using PyInstaller won't work right now.

The numpy.core.multiarray failed to import error is the single most common issue for numpy, it just means the numpy install was incomplete (many root causes possible).

Also given that reinstalling numpy solves this, I don't think there's anything to do on the PyTorch side.

@mruberry
Copy link
Collaborator

Closing this issue per @rgommers's comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: numpy Related to numpy support, and also numpy compatibility of our operators module: windows Windows support for PyTorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module windows-triaged
Projects
None yet
Development

No branches or pull requests

8 participants