{"id":132402,"date":"2023-03-12T06:19:35","date_gmt":"2023-03-12T06:19:35","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=1202016"},"modified":"2023-03-12T06:19:35","modified_gmt":"2023-03-12T06:19:35","slug":"python-to-exe-how-to-make-a-python-script-executable","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2023\/03\/12\/python-to-exe-how-to-make-a-python-script-executable\/","title":{"rendered":"Python to .exe \u2013 How to Make a Python Script Executable?"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;1202016&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/p><\/div>\n<p>I have a confession to make. I use Windows for coding Python. <\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"225\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image.gif\" alt=\"\" class=\"wp-image-1202025\"\/><\/figure>\n<p>This means that I often need to run my practical coding projects as Windows <code>.exe<\/code> files, especially if I work with non-technical clients that don&#8217;t know how to run a Python file.<\/p>\n<p>In this tutorial, I&#8217;ll share my learnings on making a Python file executable and converting them to an <code>.exe<\/code> so that they can be run by double-click.<\/p>\n<h2>PyInstaller<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"163\" height=\"165\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-140.png\" alt=\"\" class=\"wp-image-1202047\"\/><\/figure>\n<\/div>\n<p>To make a Python script executable as a <code>.exe<\/code> file on Windows, use a tool like <code><a rel=\"noreferrer noopener\" href=\"https:\/\/pyinstaller.org\/en\/stable\/\" data-type=\"URL\" data-id=\"https:\/\/pyinstaller.org\/en\/stable\/\" target=\"_blank\">pyinstaller<\/a><\/code>. PyInstaller runs on Windows 8 and newer.<\/p>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/2b50.png\" alt=\"\u2b50\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Pyinstaller<\/strong> is a popular package that bundles a Python application and its dependencies into a single package, including an <code>.exe<\/code> file that can be run on Windows without requiring a Python installation.<\/p>\n<p>Here are the general steps to create an executable file from your Python script using Pyinstaller:<\/p>\n<ol>\n<li>Install Pyinstaller by opening a command prompt and running the command: <code>pip install pyinstaller<\/code> or <code>pip3 install pyinstaller<\/code> depending on your <a href=\"https:\/\/blog.finxter.com\/how-to-check-your-python-version\/\" data-type=\"post\" data-id=\"1371\" target=\"_blank\" rel=\"noreferrer noopener\">Python version<\/a>.<\/li>\n<li>Navigate to the directory where your Python script is located in the command prompt using <code>cd<\/code> (command line) or <code>ls<\/code> (PowerShell).<\/li>\n<li>Run the command: <code>pyinstaller --onefile your_script_name.py<\/code>. This command creates a single executable file of your Python script with all its dependencies included.<\/li>\n<li>After the command completes, you can find the executable file in a subdirectory called <code>dist<\/code>.<\/li>\n<li>You can now distribute the executable file to users, who can run it on their Windows machines by double-clicking the <code>.exe<\/code> file.<\/li>\n<\/ol>\n<h2>What Does the &#8211;onefile Option Mean?<\/h2>\n<p>The <code>--onefile<\/code> file specifier is an option for Pyinstaller that tells it to package your Python script and all its dependencies into a single executable file. <\/p>\n<p>By default, Pyinstaller will create a directory called <code>dist<\/code> that contains your script and a set of related files that it needs to run. However, using the <code>--onefile<\/code> option, Pyinstaller will generate a single <code>.exe<\/code> file, which is more convenient for the distribution and deployment of the application.<\/p>\n<h2>1-Paragraph Summary<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">To convert a Python file <code>my_script.py<\/code> to an executable <code>my_script.exe<\/code> using Pyinstaller, install Pyinstaller using <code>pip install pyinstaller<\/code>, navigate to the script directory in the command prompt, run <code>pyinstaller --onefile my_script.py<\/code>, then locate the executable file in the <code>dist<\/code> folder.<\/p>\n<p>If you want to keep improving your coding skills, check out our free Python cheat sheets!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) I have a confession to make. I use Windows for coding Python. This means that I often need to run my practical coding projects as Windows .exe files, especially if I work with non-technical clients that don&#8217;t know how to run a Python file. In this tutorial, I&#8217;ll share my learnings [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857,41],"tags":[73,468,528],"class_list":["post-132402","post","type-post","status-publish","format-standard","hentry","category-python-tut","category-windows-information","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=132402"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132402\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=132402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=132402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=132402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}