2

I know there have been a bunch of questions already asked regarding this but none of them really helped me. Let me explain the whole project scenario so that I provide a better clarity to my problem. The directory structure is somewhat like this shown below:

Project Directory Layout

enter image description here

I need to convert this whole GUI based project (The main file is using Tkinter module to create GUI) into main.exe which I can share with others while making sure that all the additional files work exactly the same way it is working now when I run this main.py via Command Prompt. When I use this command with pyinstaller -

"pyinstaller --onefile --noconsole main.py"

It creates main.exe which shows "Failed to execute script" on running. Please provide me a detailed explanation on what should I do to achieve what I have stated above. Thank you in advance.

Humayun Ahmad Rajib
  • 1,502
  • 1
  • 10
  • 22
Gizmosoft
  • 133
  • 1
  • 5
  • You need to add those directories using `Tree(...)` in the SPEC file. See [document](https://pyinstaller.readthedocs.io/en/stable/advanced-topics.html#the-tree-class). – acw1668 Jun 08 '20 at 07:24

2 Answers2

1

pyinstaller uses a few dirty tricks to compress a bunch of files into one

I recommend using cx_Freeze instead along with inno setup installer maker

do pip install cx_Freeze to install that and go here for inno setup

then copy the following into a file named setup.py in the same folder as your project

from cx_Freeze import setup, Executable

setup(name = "YOUR APP NAME" ,
      version = "1.0.0" ,
      description = "DESCRIPTION" ,
      executables = [Executable("PYTHON FILE", base = "Win32GUI")]
)

lastly run python setup.py build

if you want as onefile download this file here

just edit the file a bit and use inno compiler to make into installer

  • 1
    Thanks for telling me about cx_freeze. It certainly took me a while to fix all the bugs and understand it a bit but it was totally worth it. Thanks a ton for your much needed help. :D – Gizmosoft Jun 11 '20 at 12:02
  • That download link seem dead. Please provide the code here, if not too long or a better source, like your own gist, for example. – not2qubit Oct 20 '20 at 19:37
  • Here's [inno setup on github](https://github.com/jrsoftware/issrc). – not2qubit Oct 20 '20 at 19:39
1

Suppose our project has the following structure.

MyApp
  |-models
  |  |-login.kv
  |-data
  |  |-words.json
  |  |-audio.tar.gz
  |-fonts
  |  |-FredokaOne.ttf
  |-images
  |  |-gb.pngsound.png
  |  |-icon.ico
  |-main.py
  |-main.kv
  |-draw.py
  |-image.py

and depends on the following packages:

- kivy
- kivymd
- ffpyplayer
- gtts
  1. First things first is to install cx_Freeze.
pip install cx_Freeze
  1. Copy the following into a file named setup.py in the same folder as your project.
# https://cx-freeze.readthedocs.io/en/latest/distutils.html

import sys
from cx_Freeze import setup, Executable

includes = []

# Include your files and folders
includefiles = ['models/','data/','fonts/','images/','main.kv','draw.py','image.py']

# Exclude unnecessary packages
excludes = ['cx_Freeze','pydoc_data','setuptools','distutils','tkinter']

# Dependencies are automatically detected, but some modules need help.
packages = ['kivy','kivymd', 'ffpyplayer','gtts']    

base = None
shortcutName = None
shortcutDir = None
if sys.platform == "win32":
    base = "Win32GUI"
    shortcutName='My App'
    shortcutDir="DesktopFolder"

setup(
    name = 'MyApp',
    version = '0.1',
    description = 'Sample python app',
    author = 'your name',
    author_email = '',
    options = {'build_exe': {
        'includes': includes,
        'excludes': excludes,
        'packages': packages,
        'include_files': includefiles}
        }, 
    executables = [Executable('main.py', 
    base = base, # "Console", base, # None
    icon='images/icon.ico', 
    shortcutName = shortcutName, 
    shortcutDir = shortcutDir)]
)
  1. Lastly run.
python setup.py build

This command will create a subdirectory called build with a further subdirectory starting with the letters exe. and ending with the typical identifier for the platform that distutils uses. This allows for multiple platforms to be built without conflicts.

On Windows, you can build a simple installer containing all the files cx_Freeze includes for your application, by running the setup script as:

python setup.py bdist_msi

Cx_freeze references

ivansaul
  • 179
  • 2
  • 6