Python Forum
How can I make a python script create an EXE?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I make a python script create an EXE?
#22
When I changed the base to console and tried again, the EXE gives the exact same error except now it shows in in the EXE console and not as a popup as it used to.

But you know what? I think this will never be solved until I REALLY tell you guys what I'm making.
I want to make a text encrypter, which when text is input, it encrypts it with the algorithm I made and creates another .py script that decrypts the text. But so no one can read the letter codes created I want the program to be in EXE form, but that will create a .py script which I also want in EXE form. So what I want to do is create an EXE out of the main program with pyinstaller, then I want that to create the decryption program and then compile it so that both are EXEs. Here is what I have till now:

PyEncrypt 2.0.py:
import os
import random
import time

logo = "\n ======================= PyEncrypt 2.0 ========================\n"

def initialize():
    os.system('title PyEncrypt 2.0')
    os.system('cls')
    os.system('color 0a')
    os.system('mode con: cols=64 lines=16')
    chars = str("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890-_',.:;+=()!@#$%^&*|/\\~`?><[]}{")
    global data
    data = {}

    for i in chars:
        data[i] = random.randint(1000000000, 10000000000)

def enterData():
    os.system('cls')
    print(logo)
    global filename
    filename = str(input("\n Enter a name for the output file:\n\n >>> "))
    os.system('cls')
    print(logo)
    global password
    password = str(input("\n Enter a password to protect your encrypted text:\n\n >>> "))
    os.system('cls')
    print(logo)
    textToEncrypt = str(input("\n Now enter the text you wish to encrypt:\n\n >>> "))
    OUTPUT = open(filename + ".txt", "w+")

    for i in range(len(textToEncrypt)):
        getValue = str(textToEncrypt[i])
        OUTPUT.write(str(data[getValue]) + "\n")

def createEncrypterProgram():
    DECRYPTER = open(filename + ".decrypt.py", "w+")
    DECRYPTER.write("""
import os
import time
os.system('title PyEncrypt 2.0 - Decrypt """ + '"' + filename + ".txt" + '"' + """')
os.system('cls')
os.system('color 0a')
os.system('mode con: cols=64 lines=16')
password = """ + '"' + password + '"' + """
filename = """ + '"' + filename + '"' + """
if os.path.isfile("./" + filename + ".txt"):
    os.system('cls')
else:
    os.system('cls')
    print(" ")
    print(" No file with encrypted text found!")
    time.sleep(0.5)
    exit()
os.system('cls')
print(" ")
print(" Enter the password that you used to encrypt your text:")
print(" ")
passwordCheck = str(input(" >>> "))
os.system('cls')
if password == passwordCheck:
    os.system('cls')
else:
    os.system('cls')
    print(" ")
    print(" Incorrect Password!")
    time.sleep(0.5)
    exit()
data = """ + str(data) + """
data2 = {val:key for (key, val) in data.items()}
INPUT = open(filename + ".txt", "r")
OUTPUT2 = open(filename + ".decrypted.txt", "w+")
for line in INPUT:
    OUTPUT2.write(str(data2[int(line)]))
os.system('cls')
print(" ")
print(" Decryption complete!")
time.sleep(0.5)
""")
    DECRYPTER.close()

def createCompiler():
    compiler = open("compiler.py", "w+")
    compiler.write("""
import sys
from cx_Freeze import setup, Executable

base = None
if sys.platform == "win32":
    base = "Console"

buildOptions = dict(
    packages = [ 'os', 'time'],
    excludes = [])

executables = [
    Executable(
        str(""" + '"' + "D:/Python/PyEncrypt 2.0/" + filename + '"' + """ + ".decrypt.py"),
        base = base,)]

setup(
    name='Decrypt',
    version = '2.0',
    description = 'Decrypt',
    options = dict(build_exe = buildOptions),
    executables = executables)
""")
    compiler.close()

initialize()
enterData()
createEncrypterProgram()
createCompiler()

os.system('python compiler.py build')
os.system('del compiler.py')

os.system('cls')
print(logo)
print("\n Encryption complete!")
time.sleep(0.5)
This encrypts, creates a decrypter and compiles it. However my problems are with the compiled EXE. Notice that this code creates a decrypter and then creates a compiler (the setup.py) and then runs it. The compiler should compile the decrypter. Plz help me with this and ask for any info you need. Note that this code only works on Windows!

Take the code, test it out on your PC and try to see what's wrong plz.
Thanks.
Reply


Messages In This Thread
RE: How can I make a python script create an EXE? - by ahmed_mokhles - Aug-25-2018, 05:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Make entire script run again every 45 mo NDillard 0 337 Jan-23-2024, 09:40 PM
Last Post: NDillard
  Trying to make a board with turtle, nothing happens when running script Quascia 3 713 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,383 Jun-29-2023, 11:57 AM
Last Post: gologica
  Make console show after script was built with Pyinstaller --NOCONSOLE? H84Gabor 0 1,233 May-05-2022, 12:32 PM
Last Post: H84Gabor
  Make my py script work only on 1 compter tomtom 14 3,946 Feb-20-2022, 06:19 PM
Last Post: DPaul
  How to create a Kibana Visualisation with python script? adzadz 0 1,285 Jul-20-2020, 06:41 AM
Last Post: adzadz
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,976 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,490 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  Make the script read from any directory falahfakhri 2 2,202 Jun-15-2020, 02:18 PM
Last Post: falahfakhri
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,330 May-28-2020, 05:27 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020