Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Now when i try to open the .exe file a black screen appears and closes immediately. I was able to get a screenshot:

enter image description here

I saw a solution like adding input() at the end of the code but it didn't work either. 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))
like image 752
Cavid Avatar asked Nov 14 '17 15:11

Cavid


3 Answers

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.

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

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

like image 63
horcrux Avatar answered Nov 19 '22 00:11

horcrux


The problem seen in the screenshot is that the Python Library cannot be found. So some configuration in your pyinstaller is wrong. Are you sure that python36.dll is in that folder? 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). Maybe you need to add this path to your Windows Path Configuration?

Please check the following two answers to see if your pyinstaller is configured correctly:

PyInstaller not working on simple HelloWorld Program

Error loading python27.dll error for pyinstaller

The situation should be similar for you with Python 3.6

like image 20
Stefan Lindblad Avatar answered Nov 19 '22 01:11

Stefan Lindblad


It's because you have created the exe file that depends on the entire folder. That's why it is working only in the dist folder.

Simple Solution:

Create the exe file using pyinstaller with onefile option. It will only creates the exe file in the dist folder and can execute anywhere we want.

use the bellow command in cmd.

pyinstaller --onefile file_name.py

like image 4
Kaveesha Silva Avatar answered Nov 19 '22 01:11

Kaveesha Silva