0

I built a python app, and I'm using Ubuntu 16.04 and python 2.7. I'm trying to compile the python script as .EXE to work on windows but I cannot find a way to make it start. I'm also having Selenium and Tkinter in my script.

Here's what my python file looks like:

import ast
import random
import thread
import time
import tkMessageBox
from Tkinter import *

import os
from selenium import webdriver
from selenium.webdriver import ActionChains
global geckodriver

if os.name == 'nt':
    geckodriver = "./geckodriver.exe"
else:
    geckodriver = "./geckodriver"

I'm also using a PNG file as tkinter icon and displayed picture in Tkinter:

photo = PhotoImage(file="smallblack.png")
root.tk.call('wm', 'iconphoto', root._w, photo)
w = Label(root, image=photo)
w.photo = photo
w.pack(side=TOP, pady=15)

and also using two text files for the script to read later:

def countlinks():
    lines = 0
    for line in open("checklinks.txt"):
        lines += 1
    return lines

but I thought this can be added later next to the generated .exe.

Now, here is my setup.py used by cx_freeze:

#setup.py
from cx_Freeze import setup, Executable

setup(
    name = "MainExe",
    version = "1.0.0",
    options = {"build_exe": {
        'packages': ["ast","random","thread","time", "tkMessageBox", "Tkinter", "os", "selenium"],
        'include_files': ['smallblack.png','geckodriver','geckodriver.exe'],
        'include_msvcr': True,
    }},
    executables = [Executable("main.py)]
    )

What am I doing wrong? When building the .exe with pyinstaller (pyinstaller main.py --onefile), the .exe builds but it doesn't open in Windows (opens a console window for 1 second and closes it), and if I'm trying to run it in CMD it says the program is too big. When trying to run cx_freeze (python setup.py build) it creates a .exe that will only open a console and nothing else happens. I've been googling this for the last 5 hours with no success. What am I doing wrong?

Nicholas Tower
  • 72,740
  • 7
  • 86
  • 98
unkn0wnx
  • 137
  • 3
  • 14
  • first, your command should be "pyinstaller --onefile main.py" The flags should come before the script – The4thIceman Oct 30 '17 at 12:17
  • I had only tkinter in my program and had troubles with the rest and used cx_freeze as mentioned in this [answer](https://stackoverflow.com/a/44433442/7032856) – Nae Oct 30 '17 at 16:04

1 Answers1

0

In the example of CX_Freeze, this is happening most likely because your build is missing one of the packages it requires. The reason it is opening the console window is because you didn't set the base to "Win32GUI". Once you do this, you'll get a dialog box which shows the error message and you can include that package in your "include" list.

Try:

    #setup.py
    from cx_Freeze import setup, Executable

    setup(
        name = "MainExe",
        version = "1.0.0",
        options = {"build_exe": {
            'packages': ["ast","random","thread","time", "tkMessageBox", "Tkinter","os", "selenium"],
            'include_files': ['smallblack.png','geckodriver','geckodriver.exe'],
            'include_msvcr': True,
        }},
        executables = [Executable("main.py", base="Win32GUI")]
        )
SixenseMan
  • 145
  • 2
  • 4