Create an exe file to run the program. How to create an .exe from a Python3 file on Windows

EXE is a format that no software can do without. It performs all processes of launching or installing programs. It can be either a full-fledged application or part of it.

There are two options for creating an EXE file. The first is the use of programming environments, and the second is the use of special installers, with the help of which various “repacks” and packages are created that can be installed in one click. Below we will look at both options using examples.

Method 1: Visual Studio Community

Let's consider the process of creating a simple program based on a programming language "Visual C++" and its compilation into Visual Studio Community.

  1. Launch the application, go to the menu "File", then click on the item "Create", and then in the list that opens to "Project".
  2. A window opens "Creating a project", in which you need to first click on the inscription "Templates", and then "Visual C++". Next, select "Win32 Console Application", set the name and location of the project. By default, it is saved in the Visual Studio Community working directory, in system folder "My documents", but you can choose a different directory if you wish. After completing the settings, click "OK".
  3. Starts "Win32 Application Configuration Wizard", in which we simply click "Next".
  4. In the next window we define the application parameters. In particular, we choose "Console Application", and in the field « Additional options» "Empty Project", while unchecking "Precompiled Header".
  5. A project is launched in which you need to add an area for writing code. To do this, in the tab "Solution Explorer" right-click on the inscription "Resource Files". Appears context menu, in which we sequentially click on "Add" And "Create element".
  6. In the window that opens "Add new element» select an item "C++ file". Next, set the name of the code file for the future application and its extension ".With". To change the storage folder, click on "Review".
  7. A browser opens, in which we specify the location and click on "Select folder".
  8. As a result, a tab appears with the title "Source.c", in which code text is typed and edited.
  9. Next, you need to copy the code text and paste it into the area shown in the image. Let's take the following as an example:
  10. #include
    #include

    int main(int argc, char* argv) (
    printf("Hello, World!");
    _getch();
    return 0;
    }

    Note: The code above is just an example. Instead, you must use your own code to create a program in Visual C++.

  11. To build the project, click on "Start Debugging" on the drop down menu "Debugging". You can just press a key "F5".
  12. After which a notification pops up warning that the current project is out of date. Here you need to click on "Yes".
  13. When compilation is complete, the application displays a console window that says "Hello, World!".
  14. We can view the created file in EXE format using Windows Explorer in the project folder.

Method 2: Installers

To automate the software installation process, so-called installers are becoming increasingly popular. With their help, software is created whose main task is to simplify the process of deploying software on a computer. Let's look at the process of creating an EXE file using Smart Install Maker as an example.

  1. We launch the program and in the tab "Information" edit the name of the future application. In the field "Save As" Click on the folder icon to determine the location where the output file will be saved.
  2. Explorer opens, in which we select the desired location and click "Save".
  3. Go to the tab "Files", where you need to add files from which the package will later be assembled. This is done by clicking on the icon «+» at the bottom of the interface. It is also possible to add an entire directory by clicking on the icon that shows a folder with a plus sign.
  4. Next, a file selection window opens, where you need to click on the folder icon.
  5. In the browser that opens, we designate the right application(in our case this is "Torrent", you can have any other) and click on "Open".
  6. As a result, in the window "Add entry" The file is displayed indicating its location. Leave the remaining options as default and click "OK".
  7. The procedure for adding the source object to the application occurs and a corresponding entry appears in a special area of ​​the software.
  8. Next, click "Requirements" and a tab opens where you need to check the list of supported operating systems. Leave a check mark in the fields "Windows XP" and everything that comes below it. Leave the recommended values ​​in all other fields.
  9. Then open the tab "Dialogues" by clicking on the corresponding inscription on the left side of the interface. Here we leave everything as default. In order for the installation to take place in background, you can check the box "Hidden installation".

  10. Once all the settings are complete, start the compilation by clicking on the down arrow icon.
  11. The specified process occurs and its current status is displayed in the window. Once compilation is complete, you can test the created package or close the window altogether by clicking the appropriate buttons.
  12. The compiled software can be found using Windows Explorer in the folder that was specified during setup.

Thus, in this article we found out that an EXE file can be created using both specialized program development environments, for example Visual Studio Community, and special installers, for example, Smart Install Maker.

Content
1.How to compile EXE
1.1 Compilation technology
1.2 Related files
2.What needs to be included in the EXE

1.How to compile EXE
1.1 Compilation technology
Epigraph:
"Oh yes Pushkin, oh yes..."
A.S. Pushkin

The technology for compiling EXEs in Visual FoxPro is quite simple. We will not be distracted by such extreme methods as entering commands like BUILD PROJECT, BUILD APP, BUILD EXE , but we will limit ourselves to the conveniences provided by the VFP graphical interface.
So, to create an EXE we need to click the button in the project manager "BUILD...". By selecting the option in the dialog box that opens Win32 executable/COM server (EXE) we press OK. ALL. ;-)
“How is everything?” - you ask - “How about what name to save the file under?”
I agree... It is necessary to indicate, otherwise everything will be in vain.
By the way, I think it would be useful to remind you that in order for the compilation process to be successful, you need to fill the project manager with the files of your program, one of which must be as main (in the project manager the name of this file is in bold), i.e. . the file that will be executed first. By default, the first program file (*.prg) or form file (*.scx) included in the project is installed as the main program.
In general, everything is quite simple! Just..?
Now about the sad...

1.2 Related files
Epigraph:
"...and when you turn it on, it doesn't work!"
M. Zhvanetsky

All the hassles of the application compilation stage are already over, and you, proud of the awareness of your own superiority over mere mortals, rush by leaps and bounds to the customer, install your application, simultaneously describing to him (the customer) how cool everything will be for him now, and counting in your mind which screw you need to buy something to have left over for beer, suddenly you come across the fact that your super-duper program doesn’t make any money. Sad. It's a shame. And most importantly, you won’t have a new hard drive or whatever you planned to buy from your fee...

The thing is that the .exe we compiled is not a self-contained executable file. This pseudo-executable requires support libraries (.dlls) to function properly. I won’t go into much detail about this, but will simply give the names of the files necessary for the application to work properly.
In principle, up to version 6 inclusive, you can use the standard one to transfer the application to the client machine. Setup Wizard, which independently prescribes everything, and in subsequent ones - InstallShield(or another installer).
All the files below are the minimum required set of files for different versions of VFP (based on materials):

VFP 8.0 msvcr70.dll, vfp8r.dll, vfp8rrus.dll, gdiplus.dll VFP 7.0 msvcr70.dll, vfp7r.dll, vfp7rrus.dll VFP 6.0 vfp6r.dll, vfp6renu.dll, vfp6rrus.dll VFP 5.0 vfpole50. dll, vfpodbc .dll, vfp500.dll, vfp5rus.dll, Foxpro.int
The above set of libraries must be placed in the program directory or in the Windows system directory. For various Windows versions these directories are different:

Win9x, WinMe c:\Windows\SYSTEM WinNT,Win2000,WinXP c:\Windows\SYSTEM32

2.What needs to be included in the EXE
Epigraph:
"To include or not to include?"
drunk electrician

Everything stated below is the personal opinion of the author, which you can ignore. But when doing it your way, remember: banging your head into a concrete wall is much more painful than taking advantage of a break made before you.
By default, ready-made.exe includes all the files necessary for the application to work - programs, forms, menus, libraries, classes, etc. except for database and table files (such files can be identified by the crossed out circle next to the file name in the project manager). All included in. exe file s after compilation will become unmodifiable (read-only). It is clear that table files (*.dbf) should not be included since they are subject to constant operations of changing and adding data, but sometimes there are cases when it is necessary to hide some static data from the user, but provide access to it by the program itself. Best place You can’t imagine the “insides” of an exe-shnik.
It is also quite a common situation when you need to “find”, or temporarily, change a report file, or when you have a whole set of reports that are unique for each user. Well, really, imagine: ten operators and ten reports each, and all this in *.exe. The only solution in this situation is to exclude these reports from the final file and supply them with the application.
In any case, the decision about which files to exclude and which to leave is up to you.

That's it, the beer is over, we need to go to the grocery store.

Best regards, Vladislav Kulak

Surely many of you at least once in your life have come across an archive with the extension .exe, not rar or even zip, but exe. The beauty of this archive is that it is self-extracting and does not require installation additional programs. Many people think that in order to create this kind of archive, some specific knowledge or programs are required, but I can assure you that this is not the case. EXE archives are created using one of several most popular archivers: WinRar and WinZip.

You probably have one of these two archivers installed on your computer, so you can safely start practicing right away. If there is no archiver at all, then you can safely install 7-zip, because it is free and freely distributed on the Internet. We will start with this archiver.

And so, prepare the folder with the files that need to be archived and right-click on it. We find an item such as 7-Zip

Another submenu pops up from which we must select the item "Add to archive..."

A window opens, look for the “Options” section, in the options the item “Create SFX archive” We place a bird opposite it. Now we pay attention to the topmost field, where the name of our future archive is. We have added an exe extension. By the way, the name of the archive can be changed. You can also specify the location where you want to save it. In principle, you can play around with the other options, but they do not affect the archive type. You can set the maximum compression level to keep the archive size as small as possible.

Now you can click on the “OK” button.

This is the file I got on my desktop:

Now let's figure out how to create exactly the same archive, but using WinRar.

In the same way, right-click on the folder and select "Add to archive":

In the window that opens, in the “General” tab, you need to in the section "Archive Options" put a bird next to the item “Create SFX archive”. Let's install some compression method. I chose "Good".

Click on the “OK” button.

The result is the following archive:

So we looked at several ways to how to create a self-extracting exe archive.

And also watch a video on the topic:

Rate this article:

We will consider creation.exe using the py2exe module library. This requires Python 3.4 and below.

If you have a higher version of Python installed, try using (below)

In this example we will look at creating .exe using an example Python3.4.

First of all, you need to create a virtual environment for Python3.4. In this example we'll call it myenv. You can choose any other name, but don't forget to make the appropriate changes.

On the terminal, type the following commands:

>py -3.4 -m venv myenv > myenv\Scripts\activate.bat

IN command line prefix will appear myenv, which means that the virtual environment named myenv is loaded. All teams Python will now use the new virtual environment.

Now let's install py2exe(https://pypi.python.org/pypi/py2exe~~HEAD=dobj) in our virtual environment:

>pip install py2exe

And finally, to create a single EXE file, in our virtual environment we run the command:

>python -m py2exe.build_exe hello.py -c --bundle-files 0

(replace hello.py to the name of your script. If the script is in a different folder, then you need to use the full path to your script, for example, C:\Projects\Python\hello.py). This will create a DIST folder which contains executable file. For quick access to it, type in the terminal:

> explorer dist

You will see the path to the folder where the EXE file is located.

Note: When executed, a window will open and disappear as quickly as it appeared.
This happens because operating system automatically closes the terminal in which the console program is finished.
In order to change this situation, you can add the line

> input ("Click to exit...")

at the end of the file Python. The interpreter will wait for user input and the window will remain open until the user presses enter.

You can study the usage in detail py2exe in the documentation on the module page: https://pypi.python.org/pypi/py2exe
Exiting the virtual environment is done with the command

>deactivate

Method 2

Via command Windows string install pyinstaller:

> pip install pyinstaller

On the command line, go to the folder where the file is located

Cd c:\...

Then on the command line we type the command

Pyinstaller --onefile example.py

Instead of exapmle.py use the name of the file from which you want to create the exe file.

In a couple of minutes everything is ready! Most likely, the exe file will be located in the created subfolder dist

HomeLisp(at least in the proposed version) is not capable of compiling Lisp code into microprocessor instructions. Therefore, to create autonomous executable files, a technology is used that can be conventionally called pseudo-EXE.

The essence of this technology is as follows.

In delivery HomeLisp includes a stub executable file that contains the kernel HomeLisp. The size of this file is about two hundred kilobytes. When creating an EXE file, a copy of the stub file is first made with a name specified by the developer. All further manipulations are performed with the created copy, which we will further call target file.

Let's assume that a developer has written and uploaded a series of functions that together make up application. When creating an EXE file, all functions chosen by the developer are assigned to the “tail” of the target file. In addition to these functions, the so-called “tail” of the target file is written. starting S-expression, as well as user-defined environment settings HomeLisp(sizes of internal stacks, number of dynamic objects, etc.)

When the target file is launched, control is first taken over by the kernel initialization program. HomeLisp, which then reads all user-saved functions from the file and loads them into the Lisp environment. After this, the block receives control starting S-expression, and the program provided by the developer begins to be executed.

Let's look at the process of creating an EXE file using a simple practical example: let's create a dialog program that will calculate greatest common divisor two integers using the Euclidean algorithm. This example is not so useless: since HomeLisp works with integers of unlimited capacity, writing a similar example in any common programming environment (VB, C++, Delphi) would require significant effort...

Function *GCD has the following form:

(defun *gcd (x y) (cond ((eq x y) x) ((greaterp y x) (*gcd y x)) ((eq (remainder x y) 0) y) (T (*gcd y (remainder x y))) )) ==> *gcd (*gcd 655 72) ==> 1 (*gcd 655 75) ==> 5 (*gcd 65536 4096) ==> 4096

Call examples show the functionality of the function. Next, you need to create a dialog shell to call this function. In the simplest case, this shell can be organized as follows:

Request (via function ASK) first operand;

Request for the second operand;

Calculation of the result;

Displaying the result using a function SAY ;

Let's write a defining expression for the function GCD-1, in which the above algorithm will be implemented:

(defun GCD-1 nil (prog (a1 a2) (setq a1 (str2fix (Ask "Enter the first operand"))) (setq a2 (str2fix (Ask "Enter the second operand"))) (TRY (say (fix2str (* gcd a1 a2))) EXCEPT (say "Error!"))))

Please note that the result of the call ASK has type STRING, and the function *GCD requires operands of type FIXED. Therefore, before assigning user-supplied values ​​to local variables, a1 And a2, these values ​​should be converted to type FIXED(what are function calls used for? STR2FIX).

Further, since a dialog program intended for the end user is being prepared, it should be provided possible errors. This is why the calculation of the greatest common divisor is done critical section of code using a function call TRY If a failure occurs during the calculation process, the program will not “crash”, but will display the message “Error!”

If you execute the function GCD-1 from the development environment, the first operand prompt window will be displayed:


The user enters the first operand and presses the button OK; A window asking for the second operand appears:


The user enters the second operand, presses the button OK and gets the result:


Now let's build based on the debugged function GCD-1 executable file. To do this, being in the development environment, select the main menu item EXE file or click the button on the toolbar with the following icon:


In both cases, the EXE file build window will open:



To create an EXE file, you must follow these steps:

Set the name of the EXE file. The name (and path) of the future EXE file are specified in the combo box in the upper left corner of the EXE file creation form. The name and path can be set manually, or you can click the "..." button and select the directory and name using the standard dialog Save as. By default a file is created noname.exe in the current directory.

In the input area "Starting S-Expression" it is necessary to specify the code from which the execution of the future application will begin. The starting S-expression can be a function call. If you need to define a starting S-expression consisting of several calls, then these calls should be “enclosed” in PROG- design.

The listed actions are the minimum necessary. In addition, the user can additionally do the following:

In the list entitled "Functions, constants, variables", clear the checkboxes next to objects whose presence is not necessary for the application to run. This action will slightly increase the execution speed of the application;

Change the settings values ​​in the list located in the upper right corner. The sequence of actions when replacing parameter values ​​will be described below;

Reset the "Display dispatch form at startup" checkbox. If this checkbox is left selected, a special icon will be displayed when the application starts. control room form. This form can be given a title (in the corresponding input field). Using the dispatch form is convenient for debugging.

Select or clear the "Notify me when complete" checkbox. If this checkbox is checked, a message will be displayed before the application terminates.

The window for creating an EXE file with the minimum required set of parameters can look like:



Next, you need to click the button with the green check mark. If the ordered EXE file already exists, HomeLisp will prompt you to confirm overwriting the file or specify a new name. After which, upon successful completion, the following message is displayed:


You can make sure that the EXE file appears in the current directory gcd-1.exe, when launched, the described dialogue with the user occurs.

If, when creating an EXE file, select the “Display dispatch form at startup” checkbox and set the form title:


Then, when executing the resulting EXE file, a dispatch form like this is displayed in the upper right corner of the screen:


When you select the Start menu item (or click the corresponding button below), the application begins to run. After the application is completed, the dispatch form remains on the screen, allowing you to run the application multiple times. To permanently terminate the application, you need to select the "Exit" menu item (or click the button below).

If an error occurs during the execution of an application with a dispatch form, information about the error is displayed in the output area, which is normally hidden. For example, if you make the starting S-expression a call to a non-existent function (unknown), then when executed, the image below will appear:


Using the dispatch form allows you to forcefully stop the application. To do this, use the "Stop" menu item and the button located below (both the menu item and the button are active only while the application is running). If, for example, the calculation of the factorial of a sufficiently large number is specified as the starting expression, then you can see the menu item and the stop button:


If you press “Stop” during execution, the program execution is interrupted:


The main menu item "Windows" of the dispatch form (and the corresponding command button) will be active when at least one graphic window is created during application execution. When you select the "Windows" item (or click on the button located below), the graphic window manager is called up.

The mode for building EXE files with a dispatch form is intended to facilitate debugging of applications. If you do not use the dispatch form, then manage graphic windows The developer himself will have to do it, and if the application freezes, he will have to use the OS task manager to remove it.

If you need to change the value of any setting parameter (stack size, number of tokens, etc.), you must click on the desired line in the "Parameters" list. The numeric value of the corresponding parameter will be transferred to the input area located below the list:



As second example of creating an EXE file, consider the previous problem (calculating GCD), but with a windowed graphical interface. To do this, we will create a dialog (as described), on the form of which we will place three labels, three input fields and two buttons. Let's assign a handler procedure to one of the buttons, in which we will calculate the GCD of the numbers entered in the first and second input fields and enter the calculated GCD into the result field. The second button click handler will close and destroy the dialog. The dialog form with controls may look like the one below:


Program code, generated by the designer, may look like this:

(prog nil (dlgCreate "_Dlg_ 419 233 "Greatest common divisor:") (dlgAddControl "_Dlg_ "_LBL_1 _LABEL 14 15 100 21 "("Tahoma" 14.25 1 0 0) "First:" 0 &H80000012 &H8000000F) (dlgAddControl " _Dlg_ "_TXT_1 _TEXT 155 13 248 31 "("Tahoma" 14 1 0 0) "" 0 &H80000008 &H80000005) (dlgAddControl "_Dlg_ "_LBL_2 _LABEL 12 59 133 26 "("Tahoma" 14.2 5 1 0 0) "Second: " 0 &H80000012 &H8000000F) (dlgAddControl "_Dlg_ "_TXT_2 _TEXT 156 56 247 31 "("Tahoma" 14 1 0 0) "" 0 &H80000008 &H80000005) (dlgAddControl "_Dlg_ "_L BL_3 _LABEL 13 101 127 27 "("Tahoma" 14, 25 1 0 0) "N.O.D." 0 &HFF &H8000000F) (dlgAddControl "_Dlg_ "_TXT_3 _TEXT 157 98 247 31 "("Tahoma" 14 1 0 0) "" 0 &HFF &H80000005) (dlgAddControl "_Dlg_ " _BUT_1 _BUTTON 24 148 180 50 "("Tahoma" 8.25 1 0 0) "Calculate") (dlgPutPicture "_BUT_1 7) (dlgAddControl "_Dlg_ "_BUT_2 _BUTTON 213 149 180 50 "("Tahoma" 8.25 1 0 0) "Close") (dlgPutPicture "_BUT_2 36) // // CLICK event handler for the _BUT_2 button // (defun _BUT_2_Click Nil (prog Nil (dlgHide "_DLG_) (dlgDestroy "_DLG_) (gc))) // // Purpose of the procedure -events _BUT_2_Click control _BUT_2 // (dlgSetEvent "_BUT_2 "_BUT_2_Click) // // CLICK event handler for the button _BUT_1 // (defun _BUT_1_Click Nil (prog (a1 a2) (setq a1 (str2fix (dlgGetText "_TXT_1))) (setq a2 (str2fix (dlgGetText "_TXT_2))) (TRY (dlgPutText "_TXT_3 (fix2str (*gcd a1 a2))) EXCEPT (dlgPutText "_TXT_3 "Error!!!")))) // // Assigning the event procedure _BUT_1_Click control _BUT_1 // (dlgSetEvent "_BUT_1 "_BUT_1_Click) // // Displaying the dialog _Dlg_ // (dlgShow "_Dlg_))

In order to build an EXE file, you need to load a function into the Lisp environment and write a starting expression to display the dialog. The easiest way is to “immerse” the above PROG-construction into function MAIN without parameters. Then the starting S-expression to run the EXE file will be the call (main). So, if you load the following functions into the Lisp environment:
// // Finding the greatest common divisor // (defun *gcd (x y) (cond ((eq x y) x) ((greaterp y x) (*gcd y x)) ((eq (remainder x y) 0) y) (T (*gcd y (remainder x y))))) // // Dialog display program _Dlg_ // (defun main nil (prog nil (dlgCreate "_Dlg_ 419 233 "Greatest common divisor:") (dlgAddControl "_Dlg_ "_LBL_1 _LABEL 14 15 100 21 "("Tahoma" 14.25 1 0 0) "First:" 0 &H80000012 &H8000000F) (dlgAddControl "_Dlg_ "_TXT_1 _TEXT 155 13 248 31 "("Tahoma" 14 1 0 0) "" 0 &H800 00008 &H80000005) (dlgAddControl "_Dlg_ "_LBL_2 _LABEL 12 59 133 26 "("Tahoma" 14.25 1 0 0) "Second:" 0 &H80000012 &H8000000F) (dlgAddControl "_Dlg_ "_TXT_2 _TEXT 156 56 7 31 "("Tahoma" 14 1 0 0) "" 0 &H80000008 &H80000005) (dlgAddControl "_Dlg_ "_LBL_3 _LABEL 13 101 127 27 "("Tahoma" 14.25 1 0 0) "N.O.D." 0 &HFF &H8000000F) (dlgAddControl "_D lg_ "_TXT_3 _TEXT 157 98 247 31 "(" Tahoma "14 1 0 0 0)" "0 & hff & h800005) (dlgaddcontrol" _dlg_ "_but_1 _button 24 148 180 50" ("Tahoma" 8.25 1 0 0 0 0 0 0 0 0 0 0 0) _BUT_1 7) (dlgAddControl "_Dlg_ "_BUT_2 _BUTTON 213 149 180 50 "("Tahoma" 8.25 1 0 0) "Close") (dlgPutPicture "_BUT_2 36) // // CLICK event handler for the _BUT_2 button // (defun _BUT_2_Click Nil (prog Nil (dlgHide "_DLG_) (dlgDestroy "_DLG_) (gc)) // // Assigning the event procedure _BUT_2_Click to the control _BUT_2 // (dlgSetEvent "_BUT_2 "_BUT_2_Click) // // CLICK event handler for the _BUT_1 button // (defun _BUT_1_Click Nil (prog (a1 a2) (setq a1 (str2fix (dlgGetText "_TXT_1))) (setq a2 (str2fix (dlgGetText "_TXT_2))) (TRY (dlgPutText "_TXT_3 (fix2str (*gcd a1 a2) )) EXCEPT (dlgPutText "_TXT_3 "Error!!!")))) // // Assigning the event procedure _BUT_1_Click to the control _BUT_1 // (dlgSetEvent "_BUT_1 "_BUT_1_Click) // // Displaying the dialog _Dlg_ // (dlgShow "_Dlg_ )))

and then build the EXE file gcd-2.exe, by setting following parameters:


It will work out a fully functional EXE file. You can run it and make sure that GCD considered correct:

Review