MigRome
MigRome

Reputation: 1155

py2exe: how to generate .exe for application with GUI in Python

I want to generate for Windows platform the executable file of my Python GUI application.
- I'm using two .py OO scripts
- The first script (processcls.py) contains this header:

from lxml import html
from urllib import urlopen
import os, re, sys, time

- The second script contains this header:

from processcls import *
from Tkinter import *
import Queue, threading, tkFileDialog, ttk, tkMessageBox, win32clipboard

- And this is my py2exe script. The problem is that I can't see any GUI created. So I don't clear know where is my mistake in the code.

from distutils.core import setup
import py2exe
setup(
    name='MyApplic',
    author='amazon',
    author_email='[email protected]',
    windows=[
        {
            'script':"init.py",
            'uac_info': "requireAdministrator","icon_resources": [(1, "favicon.ico")]
        }
    ], 
    options=
        {
            'py2exe':{
                'includes': ['lxml.etree', 'lxml._elementpath', 'gzip', 'processcls'],
                'packages': ['lxml', 'urllib', 'Tkinter'],
                'bundle_files': 1,
                'compressed'  : True
        }
    },
    zipfile = None
)

Any suggestions? I'm using Tkinter as a GUI gramework and Python 2.7

Thanks Migrome

Upvotes: 1

Views: 9388

Answers (2)

Martí Climent
Martí Climent

Reputation: 557

All credits to https://www.youtube.com/watch?v=OZSZHmWSOeM

If you are unable to run the pip command, follow this guide:

  1. Download this zip: https://github.com/brentvollebregt/auto-py-to-exe
  2. Extarct the zip file.
  3. In the cmd, browse to the main folder of the program, in my case C:\Program Files\auto py to exe:

    cd C:\Program Files\auto py to exe

  4. Install the repository using this command (continue in the cmd):

    pip install -r requirements.txt

  5. When finished, run the run.py file from the same folder or just type in the cmd: (Tip: Create a shortcut for this file to the desktop for future usage!)

    python run.py

An "Auto Py To Exe" GUI should appear in the screen.

  1. Select your .py file or paste the path on "Script Location"

  2. Select One File mode.

  3. If you are using a GUI like Tkinter, select "Window Based (Hide the console)". If not, select "Console Based"

  4. Select an icon if you want and select additional files if the code has external files.

  5. In "Advanced", select the output folder.

  6. Click on the "CONVERT .PY TO .EXE" BUTTON. When the process has finished, you'll have a .exe file in your output folder. Execute-it. It should work exactly as the .py other.

Upvotes: 0

Martí Climent
Martí Climent

Reputation: 557

go to cmd and type

pip install auto-py-to-exe

wait until it finishes, and then, run

auto-py-to-exe

on cmd. A GUI should appear. Follow the instructions given.

Upvotes: 3

Related Questions