Python: DLL 加载失败: %1 不是有效的 Win32 应用程序
Python: DLL load failed: %1 is not a valid Win32 application
我已经成功安装了最新版本的 Numpy,我正在使用 Python 3.4,我不明白这个错误:
Traceback (most recent call last):
File "C:\Python34\LUdecomp.py", line 1, in <module>
import numpy as np
File "C:\Python34\lib\site-packages\numpy\__init__.py", line 170, in <module>
from . import add_newdocs
File "C:\Python34\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Python34\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Python34\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Python34\lib\site-packages\numpy\core\__init__.py", line 6, in <module>
from . import multiarray
ImportError: DLL load failed: %1 is not a valid Win32 application.
代码:
import numpy as np
from sys import argv
script, filename = argv
txt = open(filename)
header = txt.readline().split()
inputArray = map(float, txt.readline().split())
txt.close()
inputMat = np.mat(inputArray)
inputMat.reshape(int(header[0]), int(header[1]))
inputMat.shape()
#takes q2data as input
def lu(A):
#Decomposes a nxn matrix A by PA=LU and returns L, U and P.
n = len(A)
L = [[0.0] * n for i in xrange(n)]
U = [[0.0] * n for i in xrange(n)]
#Creates the pivoting matrix for m.
n = len(A)
ID = [[float(i == j) for i in xrange(n)] for j in xrange(n)]
for j in xrange(n):
row = max(xrange(j, n), key=lambda i: abs(A[i][j]))
if j != row:
ID[j], ID[row] = ID[row], ID[j]
p = ID
#perform matrix multplication
TA = zip(*A)
A2 = [[sum(eP*ea for eP,ea in zip(P,a)) for a in TA] for P in p]
for j in xrange(n):
L[j, j] = 1.0
for i in xrange(j+1):
s1 = sum(U[k, j] * L[i, k] for k in xrange(i))
U[i, j] = A2[i, j] - s1
for i in xrange(j, n):
s2 = sum(U[k, j] * L[i, k] for k in xrange(j))
L[i, j] = (A2[i, j] - s2) / U[j, j]
return (L, U, p)
print (lu(inputMat))
您已经安装了 64 bit
版本的 numpy,并且正在使用 32 bit
版本的 python,反之亦然。您可以从 here
安装预构建的二进制文件
我发现的聪明解决方案是简单地进行 pip numpy 升级,pip 将卸载错误的 32 位或 64 位安装并安装所需的位。 另外,您可以指定您想要的版本。
我已经成功安装了最新版本的 Numpy,我正在使用 Python 3.4,我不明白这个错误:
Traceback (most recent call last):
File "C:\Python34\LUdecomp.py", line 1, in <module>
import numpy as np
File "C:\Python34\lib\site-packages\numpy\__init__.py", line 170, in <module>
from . import add_newdocs
File "C:\Python34\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Python34\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Python34\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Python34\lib\site-packages\numpy\core\__init__.py", line 6, in <module>
from . import multiarray
ImportError: DLL load failed: %1 is not a valid Win32 application.
代码:
import numpy as np
from sys import argv
script, filename = argv
txt = open(filename)
header = txt.readline().split()
inputArray = map(float, txt.readline().split())
txt.close()
inputMat = np.mat(inputArray)
inputMat.reshape(int(header[0]), int(header[1]))
inputMat.shape()
#takes q2data as input
def lu(A):
#Decomposes a nxn matrix A by PA=LU and returns L, U and P.
n = len(A)
L = [[0.0] * n for i in xrange(n)]
U = [[0.0] * n for i in xrange(n)]
#Creates the pivoting matrix for m.
n = len(A)
ID = [[float(i == j) for i in xrange(n)] for j in xrange(n)]
for j in xrange(n):
row = max(xrange(j, n), key=lambda i: abs(A[i][j]))
if j != row:
ID[j], ID[row] = ID[row], ID[j]
p = ID
#perform matrix multplication
TA = zip(*A)
A2 = [[sum(eP*ea for eP,ea in zip(P,a)) for a in TA] for P in p]
for j in xrange(n):
L[j, j] = 1.0
for i in xrange(j+1):
s1 = sum(U[k, j] * L[i, k] for k in xrange(i))
U[i, j] = A2[i, j] - s1
for i in xrange(j, n):
s2 = sum(U[k, j] * L[i, k] for k in xrange(j))
L[i, j] = (A2[i, j] - s2) / U[j, j]
return (L, U, p)
print (lu(inputMat))
您已经安装了 64 bit
版本的 numpy,并且正在使用 32 bit
版本的 python,反之亦然。您可以从 here
我发现的聪明解决方案是简单地进行 pip numpy 升级,pip 将卸载错误的 32 位或 64 位安装并安装所需的位。 另外,您可以指定您想要的版本。