-1

I have ten .py scripts that all function as one program. I call these scripts with the following code:

def tkinter2():
    ret = os.system('python delete_order.py')
    if ret:
        load_data()

My issue is that I want to combine all of these scripts into one script, then make it one .exe file with pyinstaller.

My issue is that every script has a different tkinter to open and separate information to extract from my database. It might be as simple as defining variables and reordering my script into one, but that would be a much larger task to evaluate single-handed.

If it would be possible for me to wrap up(so to speak) all of these scripts into one bundle installation file to distribute, that would be the ideal, with minimal impact on clients.

Zahra Bayat
  • 355
  • 3
  • 15
ReflexTechR
  • 41
  • 1
  • 9
  • While this possible, and this comment is probably off-topic, I don't think python is the ideal language for creating .exe files. You should look into languages that actually compile into bytecode, like C++. Python projects usually stay folders of .py scripts, that's just how a scripting language is designed to be used. – Finomnis Oct 30 '20 at 11:59
  • Does this answer your question? [Create a single executable from a Python project](https://stackoverflow.com/questions/12059509/create-a-single-executable-from-a-python-project) – Finomnis Oct 30 '20 at 12:02
  • @Finomnis To be completely honest, I developed and played around with python and ended up with a much larger program that I initially planned. A lot more time went into the project and it is running the way I want it to and I can easily edit it. I do believe that there is a solution for converting this to C++, but I am very unfamiliar with C++ as I do not have any experience with it. What compiler should I use then? - (probably sounds a bit neurotic, but i just code for fun) – ReflexTechR Oct 30 '20 at 12:12
  • I understand that and it is a very valid reason for your question. Nonetheless, I don't think merging your scripts will accomplish anything, and how to create an executable from a python project is already well-discussed, see my link. Please flag this question as a duplicate if the linked thread answers your question. – Finomnis Oct 30 '20 at 12:14
  • @Finomns Any regard with `pyinstaller` seems to have a problem with multiple script or with the placement of reading the databases. I can copy over the databases individually and install SQL on mentioned clients, but i want to be able to run one executable to access all scripts. If an example is necessary please let me know then i can comment my repo on `Github`. I tried the link, although it does help with the single script, I cant seem to select more than one script, or a project on the `auto-py-to-exe` program. Maybe I just need more experience with `pyinstaller` XD – ReflexTechR Oct 30 '20 at 12:23
  • Many big programs use pyinstaller: https://github.com/pyinstaller/pyinstaller/wiki/Projects-Using-PyInstaller For example https://github.com/mcedit/mcedit2 uses pyinstaller, and it's a lot bigger than a single script. I'm pretty sure you need more experience with PyInstaller. But I don't have any myself, so that's where my wisdom ends :) – Finomnis Oct 30 '20 at 12:31
  • Making a single file here, seems too much, your app would take almost like 1 or 2 minute plus to open up, so its better to compile into a directory using `--onedir` – Delrius Euphoria Oct 30 '20 at 13:13
  • @Cool Cloud If I use the `--onedir` commend, i will have to put in the path to the directory, correct? – ReflexTechR Nov 02 '20 at 07:56
  • @ReflexTechR What do you mean? Imagine you have a file hello.py which imports bellow.py or whatever, make a command like `pyinstaller -w --onedir hello.py` now this will create a dist folder with hello folder in it, go inside it and run the exe there, and then it will run without then need of copying any py file to that folder, but if you have any files or images with relative path, make sure to copy them to the directory and use relative paths so they dont get confusing. – Delrius Euphoria Nov 02 '20 at 08:41
  • @Cool Cloud I ran the command. I found the directory in the dist folder, but the system returned `Failed to execute script orders`. The one script is accessing the other scripts via the code mentioned above. All the information is read from a SQL database. Any normal script that i have converted with pyinstaller has worked, but not in this case. It does compile the single script, but when it opens and i want to run the other scripts, it does not open them, as it is not used as an import, but running from `os.system` – ReflexTechR Nov 02 '20 at 10:50
  • Oh i thought your were using `import` statements, I think with `os.system()` you might want to copy the files to the directory too, depending on the location you gave it – Delrius Euphoria Nov 02 '20 at 11:10
  • @CoolCloud I compile the main script with the `--onefile` command. It runs the script on my PC, but the ideal would be is to be able to distribute all parts, without installing all of the programs I have on my computer, if I wanted to use this program on a larger scale? or would it be more recommended to initialize the program on a server and access it with remote clients? – ReflexTechR Nov 02 '20 at 11:14
  • Then copy the other files on to the directory and give the relative path to the file? like `os.system('bello.py')` which means bello.py is in the same directory as hello.py, which is running the command – Delrius Euphoria Nov 02 '20 at 11:17
  • @CoolCloud So I can quite literally just copy all of the files i have on mine over to another system and it can run? I apologize for my ignorance, this is all kind of new to me. I would think you would need the sqlite3 installed as well. I get the idea, the `os.system(python bello.py)` where the python reads as the program to open the file, without the python extension in front the `os.system` it is not feasible to use. It seems that i would have to install python and SQL as extra security to run the script as is, but that would not be a problem. I just don't want to Install the compiler. – ReflexTechR Nov 02 '20 at 11:19
  • Which compiler are you referring to? Anyways take a look [here](https://stackoverflow.com/questions/61371718/how-to-give-permission-to-other-pc-to-add-data-to-my-database-in-mysql-in-my-com) – Delrius Euphoria Nov 02 '20 at 11:30
  • @CoolCloud Sorry, i meant interpreter. I am using `pyCharm` to program in, it seems easier. I believe that if i install python and sqlite on the client the frontend wont really see these programs and i would be able to restrict access. I will copy the `.exe` file with the accompanied scripts and test. Please post an answer so that I can upvote. – ReflexTechR Nov 02 '20 at 11:38
  • No its fine, this is barely an answer. Anways good luck with the project ! – Delrius Euphoria Nov 02 '20 at 11:48
  • 1
    @CoolCloud The brainstorm in the comments solved the problem, no direct answer but the advice was well received. Thank you – ReflexTechR Nov 03 '20 at 08:03

2 Answers2

0

The only options I know of are these

  • Pyinstaller
  • Py2Exe
  • Nuitka

I personally really like nuitka, check them out and read the docs for them on how to build a single binary from multiple files (make sure they include their dependencies, there's optional arguments for this)

JackofSpades
  • 113
  • 1
  • 8
0

I used pyinstaller to make an .exe file from the main script, running all of the other script through os.system. I then copied all of the corresponding files to the same directory and it ran all of the referenced scripts as programmed. I did have a slight issue with the cmd opening while using the program. I am still working on the project to avoid any unexpected issues.

ReflexTechR
  • 41
  • 1
  • 9