I created an executable with pyinstaller and it does not run

Asked

Viewed 1,939 times

-1

Hello

I created a executable with the

pyinstaller
pyinstaller --onefile -c app.py

contents of the archive app.py

print("hello world")

x = input("Qual seu nome?")

print(x)

after generated while opening the . exe it does not run, gives no error and does not appear in windows Task Manager

python== 3.8.0
pyinstaller == 3.6


100 INFO: UPX is not available.
100 INFO: Extending PYTHONPATH with paths
['C:\\...\teste pyinstaller',
 'C:\\...\\teste pyinstaller']
100 INFO: checking Analysis
125 INFO: checking PYZ
156 INFO: checking PKG
156 INFO: Building because C:\...\teste pyinstaller\build\hello\hello.exe.manifest changed
156 INFO: Building PKG (CArchive) PKG-00.pkg
1845 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
1845 INFO: Bootloader c:\...programs\python\python38-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
1845 INFO: checking EXE
1861 INFO: Rebuilding EXE-00.toc because pkg is more recent
1861 INFO: Building EXE from EXE-00.toc
1861 INFO: Appending archive to EXE C:\...\teste pyinstaller\dist\hello.exe
1892 INFO: Building EXE from EXE-00.toc completed successfully.
  • I always watch the videos of Source Code tv where they use pyinstaller, only in my case it doesn’t work

3 answers

1


I don’t know how to answer pyinstaller but you can try to use cx_Freeze.

Following these steps: (Python 3.6)

1 - Installing cx_Freeze, (open the command prompt and type: Pip install cx_Freeze).

2 - Installing idna, (Pip install idna).

3 - Create a new . py file called setup.py in the same folder as your app.py file

4 - Inside setup.py, copy the code below and save it.

5 - With shift pressed, right-click inside the app.py file directory and open the command prompt window (cmd)

6 - At the prompt, type: python setup.py build

7 - If your script runs without errors, then there were no problems in creating the executable. Look in the folder where the main file is, there should be another folder call build, with another folder inside, in it you should find the app.exe file.

Code for the archive setup py.

    from cx_Freeze import setup, Executable
    
    base = None    
    
    executables = [Executable("myfirstprog.py", base=base)]

    packages = ["idna"]
    options = {
        'build_exe': {    
            'packages':packages,
        },    
    }

    setup(
        name = "<any name>",
        options = options,
        version = "<any number>",
        description = '<any description>',
        executables = executables
    )

Remember to modify the attributes within setup.py, mainly "Executable('aquionomedoseufile.py')" and others like: name, version, Description.

  • Thank you, I’ll check

  • Filet "setup.py", line 7

  • Packages= ["idna"] invalid syntax

  • It worked out missed a ]

-1

It may be that the necessary modules are not being imported open the prompt in the folder where your project is type Pip Freeze will appear a list of Imports that are necessary for your program to work Voce needs to import them when using pyinstaller, the command to compile will look like this

pyinstaller --Hidden-import='package name_name' -Hidden-import='package name_name'... -F your program.py

then put --Hidden-import= xxxxx for each package that appeared there in the Freeze command at the end Voce can use -F or --onefile to generate 1 standalone file and finally the name of your program.py and enter.

-2

At the end of your code add an input Ex. input("Press enter to exit! ")

In my case it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.