Skip to content Skip to sidebar Skip to footer

My Python Exe Will Not Run 2 Other Python Exe's

Edit: This was fixed! I show my friends most of the python programs I make, and I sometimes make small programs for them (on commission). I made a program that runs MS Paint and wr

Solution 1:

How to simplify your code into a single script:

from threading import Thread
import pyautogui as pg
import os
import time


def main():
    t = Thread(target=open_paint)
    t.start()
    time.sleep(5)
    draw_uhoe()


def open_paint():
    os.system('C:\\WINDOWS\\system32\\mspaint.exe')


def draw_uhoe():
    print('drawing')
    pg.moveTo(400, 450, 0.1)

    # this is a U

    pg.drag(0, 200, 0.1)
    pg.drag(50, 0, 0.1)
    pg.drag(0, -200, 0.1)
    pg.moveRel(100, 200, 0.1)

    # This is an H

    pg.drag(0, -200, 0.1)
    pg.moveRel(0, 100, 0.1)
    pg.drag(50, 0, 0.1)
    pg.moveRel(0, 100, 0.1)
    pg.drag(0, -200, 0.1)

    # this is an O

    pg.moveRel(0, 100, 0.1)
    pg.moveRel(50, 0, 0.1)
    pg.drag(50, 0, 0.1)
    pg.drag(0, 100, 0.1)
    pg.drag(-50, 0, 0.1)
    pg.drag(0, -100, 0.1)

    # this is an E

    pg.moveRel(100, 0, 0.1)
    pg.drag(50, 0, 0.1)
    pg.drag(0, 50, 0.1)
    pg.drag(-50, 0, 0.1)
    pg.drag(0, -50, 0.1)
    pg.drag(0, 100, 0.1)
    pg.drag(50, 0, 0.1)

    # this is a !
    pg.moveRel(100, 0, 0.1)
    pg.drag(0, -25, 0.1)
    pg.moveRel(0, -25, 0.1)
    pg.drag(0, -150, 0.1)
    pg.moveRel(0, 200, 0.1)

main()

Having a single script is just easier in my opinion, but not entirely necessary. Once you have this made, make another python file in the same directory called setup.py:

setup.py

import sys
import os
from cx_Freeze import setup, Executable

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

# Dependencies are automatically detected, but it might need fine tuning.
additional_modules = []

build_exe_options = {"includes": additional_modules,
                     "packages": ["threading", "pyautogui", "os", "time"],
                     "excludes": [],
                     "include_files": [
                                       os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
                                       os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')
                                       ]}

# GUI applications require a different base on Windows (the default is for a# console application).
base = Noneif sys.platform == "win32":
    base = "Win32GUI"

setup(name="LetterDrawer",
      version="1.0",
      description="U hoe!",
      options={"build_exe": build_exe_options},
      executables=[Executable("workspace.py", base=base)]) #change workspace.py to your file name

Now open a terminal in that folder and run python setup.py build. This will create an executable for you in a new directory called build. (You may have to run the command twice). Now open that folder and run the .exe to check it worked. If it did you have to send your friend the whole folder with the .exe (including all the .dlls). This will allow them to run the program without python installed (hence all the dlls). On my machine doing this with the provided code created an executable that accomplished the desired task. Let me know if you have questions on something I was unclear about, but otherwise if this fixed your problem I'd appreciate if you click that check mark by my post to accept it as the solution

Post a Comment for "My Python Exe Will Not Run 2 Other Python Exe's"