栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pyinstaller 打包后运行报ImportError: DLL load failed: 找不到指定的模块

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pyinstaller 打包后运行报ImportError: DLL load failed: 找不到指定的模块

我的环境是:
torch 1.6
cuda 10.1
scikit-image 0.18.1
scikit-learn 0.24.1
scipy 1.6.1
pyinstaller 4.5.1

报错信息

Traceback (most recent call last):
  File "server.py", line 14, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "solar_engine.py", line 7, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "EngineFactory.py", line 1, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "solar_detector.py", line 9, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "utilssort.py", line 25, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "skimageio__init__.py", line 11, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "skimageio_io.py", line 4, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "skimagecolor__init__.py", line 1, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "skimagecolorcolorconv.py", line 56, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "scipylinalg__init__.py", line 195, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "scipylinalgmisc.py", line 3, in 
  File "PyInstallerloaderpyimod03_importers.py", line 546, in exec_module
  File "scipylinalgblas.py", line 213, in 
importError: DLL load failed: 找不到指定的模块。
[4024] Failed to execute script 'server' due to unhandled exception!

还有一个可能出现的报错是scipysparselinalgisolveiterative.py。
解决方法在pyinstaller的一个issue中,出现这个问题的原因是skimage、sklearn、scipy必须在torch前import,否则会有共享库的冲突导致报错。
这个是那个大佬给的样例代码,你们可以把import顺序换一下试试

import numpy as np
import torch  # importing torch before scipy seems to trigger the issue
from scipy import linalg 

print('Testing scipy.linalg...')
a = np.array([[1., 2.], [3., 4.]])
print(linalg.inv(a))

print('Testing torch...')

dtype = torch.float
device = torch.device("cpu")
# device = torch.device("cuda:0") # Uncomment this to run on GPU

# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

# Create random input and output data
x = torch.randn(N, D_in, device=device, dtype=dtype)
y = torch.randn(N, D_out, device=device, dtype=dtype)

# Randomly initialize weights
w1 = torch.randn(D_in, H, device=device, dtype=dtype)
w2 = torch.randn(H, D_out, device=device, dtype=dtype)

learning_rate = 1e-6
for t in range(500):
    # Forward pass: compute predicted y
    h = x.mm(w1)
    h_relu = h.clamp(min=0)
    y_pred = h_relu.mm(w2)

    # Compute and print loss
    loss = (y_pred - y).pow(2).sum().item()
    if t % 100 == 99:
        print(t, loss)

    # Backprop to compute gradients of w1 and w2 with respect to loss
    grad_y_pred = 2.0 * (y_pred - y)
    grad_w2 = h_relu.t().mm(grad_y_pred)
    grad_h_relu = grad_y_pred.mm(w2.t())
    grad_h = grad_h_relu.clone()
    grad_h[h < 0] = 0
    grad_w1 = x.t().mm(grad_h)

    # Update weights using gradient descent
    w1 -= learning_rate * grad_w1
    w2 -= learning_rate * grad_w2


另外吐槽一下CSDN的一些文章,给出的解决方法不行是因为环境不一样不能直接用,但是你标题是什么什么的解决方法,点进去只有报错信息,解决方法呢???看见一个举报一个

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/350474.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号