gpt4 book ai didi

python - pyinstaller 给出 "ImportError: DLL load failed"

转载 作者:行者123 更新时间:2023-11-28 18:56:24 25 4
gpt4 key购买 nike

当我使用 pyinstaller 运行从 python 编译为 exe 的程序时,出现错误(我使用 python 2.7.16):

Traceback (most recent call last):
File "bloepie.py", line 1, in <module>
File "c:\users\stefan\appdata\local\temp\pip-install-v9ecuy\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "build\bdist.win-amd64\egg\bluetooth\__init__.py", line 37, in <module>
File "c:\users\stefan\appdata\local\temp\pip-install-v9ecuy\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "build\bdist.win-amd64\egg\bluetooth\msbt.py", line 2, in <module>
File "c:\users\stefan\appdata\local\temp\pip-install-v9ecuy\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "build\bdist.win-amd64\egg\bluetooth\_msbt.py", line 7, in <module>
File "build\bdist.win-amd64\egg\bluetooth\_msbt.py", line 6, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.
[21200] Failed to execute script bloepie

我编译它:

pyinstaller bloepie.py --onefile

this person和我有同样的问题,但他得到的唯一答案是他应该升级到 python 3 或更高版本,我不想这样做,而且它没有被标记为正确答案,所以我也不能保证如果我这样做了它会起作用。这个人有一个稍微不同的问题。我有一个“导入错误:DLL 无法加载:...”他有一个正常的导入错误(我不知道这是否有所不同,但我找不到任何相关信息)

这是我用pyinstaller编译的python代码:

import bluetooth
from pynput.mouse import Button, Controller

mouse = Controller()
may_i = 0
may_x = 0
may_y = 0
lockdown = 0

server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
server_sock.bind(("",bluetooth.PORT_ANY))
server_sock.listen(1)

bluetooth.advertise_service(server_sock, "helloService",
service_classes=[bluetooth.SERIAL_PORT_CLASS],
profiles=[bluetooth.SERIAL_PORT_PROFILE])

client_sock, address = server_sock.accept()
print "Accepted connection from ",address

while True:
may_i = 0
gata = client_sock.recv(1024)
if gata == "":
break
data = gata.split(";")
for dt in data:
if dt == "":
may_i = 1
if dt == "Down":
loci = mouse.position
may_x = 0
may_y = 0
lockdown = 0
may_i = 1
if dt == "Up":
if may_x == 1 and may_y == 1 and lockdown == 0:
mouse.press(Button.left)
mouse.release(Button.left)
may_i = 1
if may_i == 0:
print "received: %s" % dt
if dt == "x0.0":
may_x = 1
if dt == "y0.0":
may_y = 1
if dt != "x0.0" and dt != "y0.0":
lockdown = 1
if "x" in dt:
dt = dt.replace("x", "")
if "-" in dt:
dt = dt.replace("-", "")
if dt.split(".")[0] != 0:
dt = str(float(dt) * 1.5)
mouse.position = (mouse.position[0] + int(dt.split(".")[0]), mouse.position[1])
else:
if dt.split(".")[0] != 0:
dt = str(float(dt) * 1.5)
mouse.position = (mouse.position[0] - int(dt.split(".")[0]), mouse.position[1])
if "y" in dt:
dt = dt.replace("y", "")
if "-" in dt:
dt = dt.replace("-", "")
if dt.split(".")[0] != 0:
dt = str(float(dt) * 1.5)
mouse.position = (mouse.position[0], mouse.position[1] + int(dt.split(".")[0]))
else:
if dt.split(".")[0] != 0:
dt = str(float(dt) * 1.5)
mouse.position = (mouse.position[0], mouse.position[1] - int(dt.split(".")[0]))

client_sock.close()
server_sock.close()

那么这里出了什么问题呢?为什么编译后的版本不运行? (py 文件工作正常)谢谢

最佳答案

我尝试过使用钩子(Hook),但它对我的代码效果不佳。相反,我将整个 scipy 文件夹复制到 python 代码文件夹,问题就解决了。在我的电脑中,scipy 文件夹位于 "D:\Programe\Anaconda\Lib\site-packages"

希望对您有所帮助。

综上所述,我在使用pyinstaller打包的技巧如下:

  1. 需要在spec文件开头添加如下代码:
import sys  
sys.setrecursionlimit(5000)
  1. 复制高危模块到打包文件夹,避免DLL丢失错误。 (在我的工作中,Numpy、Scipy 和 Pandas 被复制了。)

  2. 对于模块丢失等其他错误,您可以通过将模块添加到 spec 文件的 hiddenimports 中来修复错误。

  3. 需要将 Pandas 更新到 1.x.x 版本。 Pandas 0.24.x 版本将显示“No module named 'pandas._libs.tslib'”并且无法通过 hiddenimports 修复。

关于python - pyinstaller 给出 "ImportError: DLL load failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57935948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com