【问题标题】:Error loading Python dll/ LoadLibrary: The specified module could not be found加载 Python dll/LoadLibrary 时出错:找不到指定的模块
【发布时间】:2017-11-14 15:17:32
【问题描述】:

我是编程新手。我用python写了一个小程序,并将其转换为带有pyinstaller的.exe文件。现在,当我尝试打开 .exe 文件时,会出现黑屏并立即关闭。我能够得到一个截图:

我看到了一个解决方案,比如在代码末尾添加input(),但它也不起作用。我的代码:

import random

print("Hello, what is your name?")
name = str(input())
print("Well, " + name + ", I think of a number between 1 and 1000. Can you guess this number in 10 chances?")
number = random.randint(1, 1001)

for guessTaken in range(1, 11):
  print("Take a guess")
  guess = int(input())
  if guess > number:
    print("The number you think is too high")
  elif guess < number:
    print("The number you think is too low")
  else:
    break

if guess == number:
  print("OK, " + name + ", you guessed the number in " + str(guessTaken) + " guesses")
else:
  print("Unfortunatelly, you couldn't find the number. The number is " + str(number))

【问题讨论】:

    标签: python pyinstaller


    【解决方案1】:

    这对我有用:

    遇到同样的问题,但后来意识到我无意中尝试执行 build 文件夹中的文件,而不是 dist 文件夹中的文件。

    看起来您可能在回溯中犯了同样的错误,因此请查看使用 dist 中的可执行文件是否无法为您解决问题

    (来源:https://stackoverflow.com/a/54119819/4607733

    【讨论】:

    • 这也解决了我的问题。为什么说明书上没有这个?根据相关问题的数量,如果是这样的话,似乎会节省很多人的时间。
    • 所以,我在用法中找到了它。但我仍然认为应该在书面指南中更清楚地说明。
    • 好的,它也在“使用 Pyinstaller”部分。
    【解决方案2】:

    截图中看到的问题是找不到 Python 库。所以你的 pyinstaller 中的一些配置是错误的。您确定 python36.dll 在该文件夹中吗?检查您的 python36.dll 所在的位置(通常在您的 python 安装所在的同一文件夹中,并且可以找到您的 python.exe)。也许您需要将此路径添加到您的 Windows 路径配置中?

    请检查以下两个答案,看看你的pyinstaller是否配置正确:

    PyInstaller not working on simple HelloWorld Program

    Error loading python27.dll error for pyinstaller

    Python 3.6 的情况应该与您类似

    【讨论】:

    • 这意味着您的程序根本无法运行。如果你的脚本被称为myfile.py,你仍然可以直接运行你的python文件,通过打开命令行并使用python myfile.py的内容运行它来查看它是否有效
    • 我查看了文件夹,里面有python36.dll。我添加了路径并重新转换了程序。还是一样。它与命令行一起工作
    • 我添加了两个类似问题的链接,看来你的pyinstaller需要更多配置。
    【解决方案3】:

    这是因为你创建了依赖于整个文件夹的exe文件。这就是为什么它只能在 dist 文件夹中工作。

    简单的解决方案:

    使用带有 onefile 选项的 pyinstaller 创建 exe 文件。 它只会在 dist 文件夹中创建 exe 文件,并且可以在我们想要的任何地方执行。

    在 cmd 中使用下面的命令。

    pyinstaller --onefile file_name.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 1970-01-01
      • 1970-01-01
      • 2018-05-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      相关资源
      最近更新 更多