简体   繁体   English

加载 Python dll/LoadLibrary 时出错:找不到指定的模块

[英]Error loading Python dll/ LoadLibrary: The specified module could not be found

I am new at programming.我是编程新手。 I wrote a small program in python and converted it to .exe file with pyinstaller .我用 python 写了一个小程序,然后用pyinstaller把它转换成 .exe 文件。 Now when i try to open the .exe file a black screen appears and closes immediately.现在,当我尝试打开 .exe 文件时,会出现黑屏并立即关闭。 I was able to get a screenshot:我能够得到一个截图:

在此处输入图片说明

I saw a solution like adding input() at the end of the code but it didn't work either.我看到了一个解决方案,比如在代码末尾添加input()但它也不起作用。 My code:我的代码:

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))

This worked for me:这对我有用:

Had the same issue but then realized that I was inadvertently trying to execute the file in the build folder instead of the dist folder.遇到了同样的问题,但后来意识到我无意中尝试在build文件夹而不是dist文件夹中执行文件。

Looks like you might be making the same mistake from your traceback so see if using the executable in dist doesn't fix it for you看起来您可能在回溯中犯了同样的错误,所以看看在dist中使用可执行文件是否不能为您修复它

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

The problem seen in the screenshot is that the Python Library cannot be found.截图中看到的问题是找不到Python库。 So some configuration in your pyinstaller is wrong.所以你的 pyinstaller 中的一些配置是错误的。 Are you sure that python36.dll is in that folder?你确定 python36.dll 在那个文件夹中吗? Check where your python36.dll is located (normally in the same folder where your python installation is located and your python.exe can be found).检查您的 python36.dll 所在的位置(通常在您的 python 安装所在的同一文件夹中,并且可以找到您的 python.exe)。 Maybe you need to add this path to your Windows Path Configuration?也许您需要将此路径添加到您的 Windows 路径配置中?

Please check the following two answers to see if your pyinstaller is configured correctly:请检查以下两个答案以查看您的 pyinstaller 是否配置正确:

PyInstaller not working on simple HelloWorld Program PyInstaller 无法处理简单的 HelloWorld 程序

Error loading python27.dll error for pyinstaller 为pyinstaller加载python27.dll错误时出错

The situation should be similar for you with Python 3.6使用 Python 3.6 的情况应该与您类似

It's because you have created the exe file that depends on the entire folder.这是因为您创建了依赖整个文件夹的exe文件。 That's why it is working only in the dist folder.这就是为什么它只能在 dist 文件夹中工作。

Simple Solution:简单的解决方案:

Create the exe file using pyinstaller with onefile option.使用 pyinstaller 和 onefile 选项创建 exe 文件。 It will only creates the exe file in the dist folder and can execute anywhere we want.它只会在 dist 文件夹中创建 exe 文件,并且可以在我们想要的任何地方执行。

use the bellow command in cmd.在cmd中使用波纹管命令。

pyinstaller --onefile file_name.py pyinstaller --onefile file_name.py

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试将.dll加载到Python中时出错“找不到指定的模块” - Error while trying to load .dll into Python “The specified module could not be found” 加载 psycopg2 模块时出错:导入 _psycopg 时 DLL 加载失败:找不到指定的模块 - Error loading psycopg2 module: DLL load failed while importing _psycopg: The specified module could not be found 加载 libmpg123.dll 失败:找不到指定的模块 - Failed loading libmpg123.dll: The specified module could not be found python Windows“ ImportError:DLL加载失败:找不到指定的模块。”加载编译的扩展名时 - python Windows “ImportError: DLL load failed: The specified module could not be found.” When loading compiled extension 部署 Tkinter:加载 Python dll/LoadLibrary 时出错 - Deploy Tkinter : error loading Python dll/ LoadLibrary LoadLibrary:找不到指定的程序 - LoadLibrary: The specified procedure could not be found 在Python中加载模块时出错:OSError:[WinError 126]找不到指定的模块 - Error when loading module in Python: OSError: [WinError 126] The specified module could not be found Python:ImportError:DLL加载失败:找不到指定的模块 - Python: ImportError: DLL load failed: The specified module could not be found Python 2.7:ImportError:DLL加载失败:找不到指定的模块 - Python 2.7: ImportError: DLL load failed: The specified module could not be found DLL加载失败:找不到指定的模块[Python] - DLL Load Failed: The specified module could not be found [Python]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM