Python pyinstaller给出了;导入错误:DLL加载失败“;

Python pyinstaller给出了;导入错误:DLL加载失败“;,python,bluetooth,pyinstaller,Python,Bluetooth,Pyinstaller,当我运行我用pyinstaller从python编译成exe的程序时,它给出了一个错误(我使用的是python 2.7.16): 回溯(最近一次呼叫最后一次): 文件“bloepie.py”,第1行,在 文件“c:\users\stefan\appdata\local\temp\pip-install-v9ecuy\pyinstaller\pyinstaller\loader\pyimod03\u importers.py”,第395行,在加载模块中 文件“build\bdist.win-amd

当我运行我用pyinstaller从python编译成exe的程序时,它给出了一个错误(我使用的是python 2.7.16):

回溯(最近一次呼叫最后一次):
文件“bloepie.py”,第1行,在
文件“c:\users\stefan\appdata\local\temp\pip-install-v9ecuy\pyinstaller\pyinstaller\loader\pyimod03\u importers.py”,第395行,在加载模块中
文件“build\bdist.win-amd64\egg\bluetooth\\uuuu init\uuuu.py”,第37行,在
文件“c:\users\stefan\appdata\local\temp\pip-install-v9ecuy\pyinstaller\pyinstaller\loader\pyimod03\u importers.py”,第395行,在加载模块中
文件“build\bdist.win-amd64\egg\bluetooth\msbt.py”,第2行,在
文件“c:\users\stefan\appdata\local\temp\pip-install-v9ecuy\pyinstaller\pyinstaller\loader\pyimod03\u importers.py”,第395行,在加载模块中
文件“build\bdist.win-amd64\egg\bluetooth\\u msbt.py”,第7行,在
文件“build\bdist.win-amd64\egg\bluetooth\\ u msbt.py”,第6行,在引导程序中__
ImportError:DLL加载失败:找不到指定的模块。
[21200]无法执行脚本bloepie
我是用以下方法编写的:

pyinstaller bloepie.py --onefile
和我有同样的问题,但他得到的唯一一个awnser是,他应该升级到python 3或更高版本,我不想这样做,而且它没有标记为正确的awnser,所以我也不能保证如果我这样做,它会工作。这个人有一个稍微不同的问题。我有一个“导入错误:DLL加载失败:…”他有一个正常的导入错误(我不知道这是否有区别,但我找不到任何关于它的信息)

以下是我使用pyinstaller编译的python代码:

导入蓝牙
从pynput.mouse导入按钮,控制器
鼠标=控制器()
我可以=0吗
may_x=0
may_y=0
锁定=0
server\u sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
服务器\u sock.bind((“”,bluetooth.PORT\u ANY))
服务器\u sock.listen(1)
bluetooth.Advertised_服务(服务器_sock,“helloService”,
服务类=[蓝牙.串行端口类],
配置文件=[bluetooth.SERIAL\u PORT\u PROFILE])
client_sock,address=server_sock.accept()
打印“已接受的连接自”,地址
尽管如此:
我可以=0吗
gata=客户端\u sock.recv(1024)
如果gata==“”:
打破
数据=gata.split(“;”)
对于数据中的dt:
如果dt==“”:
可以吗
如果dt=“向下”:
位置=鼠标位置
may_x=0
may_y=0
锁定=0
可以吗
如果dt=“向上”:
如果may_x==1和may_y==1且锁定==0:
鼠标。按下(按钮。左)
鼠标。释放(按钮。左)
可以吗
如果may_i==0:
打印“已收到:%s”%dt
如果dt==“x0.0”:
may_x=1
如果dt==“y0.0”:
may_y=1
如果dt!=“x0.0”和dt!=“y0.0”:
锁定=1
如果dt中的“x”:
dt=dt.替换(“x”,“”)
若dt中为“-”,则:
dt=dt。替换(“-”,“”)
如果dt.split(“.”[0]!=0:
dt=str(浮动(dt)*1.5)
mouse.position=(mouse.position[0]+int(dt.split(“.”[0]),mouse.position[1])
其他:
如果dt.split(“.”[0]!=0:
dt=str(浮动(dt)*1.5)
mouse.position=(mouse.position[0]-int(dt.split(“.”[0]),mouse.position[1])
如果dt中的“y”:
dt=dt.替换(“y”和“y”)
若dt中为“-”,则:
dt=dt。替换(“-”,“”)
如果dt.split(“.”[0]!=0:
dt=str(浮动(dt)*1.5)
mouse.position=(mouse.position[0],mouse.position[1]+int(dt.split(“.”[0]))
其他:
如果dt.split(“.”[0]!=0:
dt=str(浮动(dt)*1.5)
mouse.position=(mouse.position[0],mouse.position[1]-int(dt.split(“.”[0]))
客户端_sock.close()
服务器\u sock.close()
那么这里出了什么问题?为什么编译后的版本没有运行(py文件工作正常)
谢谢

为了强制pyinstaller添加缺少的dll,您可以在spec文件中添加一个。规范文件是由pyinstaller创建的,用于描述如何构建程序。但是当存在一些
dll
时,仅通过分析代码无法找到它们,因此您必须编辑此文件(有关此文件的详细信息,请参阅)

第一次运行后,您可以编辑此文件并在
分析
部分中添加一行,如下所示。我使用假dll编辑了文档中的示例:

a=分析(['minimal.py'],
pathex=['/Developer/PItests/minimal'],
二进制文件=[('C:\\path\\to\\the\\wbtapi.dll','dll'),
数据=无,
hiddenimports=[],
hookspath=无,
运行时挂钩=无,
排除=无,
密码=分组密码)
但是如果没有包名,我就不能说得更准确了

编辑:使用pybluez for win10,我认为您必须找到
wbtapi.dll
。我没有windows 10,因此我不知道它可以放在哪里


编辑bis:更多解释。

我尝试过使用钩子,但在我的代码中效果不佳。相反,我将整个scipy文件夹复制到python代码文件夹中,问题得到了解决。在我的计算机中,scipy文件夹位于
“D:\Programe\Anaconda\Lib\site packages”

希望它能帮助你

总之,我在使用pyinstaller的软件包中的提示如下:

  • 需要在等级库文件的开头添加以下代码:
  • 将高风险模块复制到打包文件夹以避免DLL丢失错误。(在我的作品中,Numpy、Scipy和Pandas都是复制品。)

  • 对于模块丢失等其他错误,您可以
    import sys  
    sys.setrecursionlimit(5000)