Convert Python Scripts to executable applications for Mac and Windows (2024)

Making your way to your directories and launching your scripts manually can get tiring, especially if it’s something you have to do every day and multiple times.

This article is part of a series of two articles that are looking to fluidify this process. The first step is to turn these scripts into applications that you can launch with a click of a button and this is what we’re gonna explore in this article. The second step is to schedule these applications to launch themselves without us having to think about it, which I will link to once the article will have been written.

There are two methods that we’re gonna look into today. One is specific to Windows and the other one works exclusively on Mac OS. You can click on the operating system that you’re using below in order to get to the part of the article that is going to work for you.

For Windows

For our Windows users out there, the solution lies in creating a Batch file that is going to navigate through our directories, find the script of your choosing and launch it for you. To do that, we need to open our text editor and write the corresponding lines :

Now, a bit of explanation :

  • REM: The line that follows REM is just a simple comment
  • ECHO: We use ECHO to return a string. This could be used in case your scripts don’t return anything and you would like to know when your script is done doing its job for instance.
  • PAUSE: This last bit is for the purpose of asking the batch file to not close the command prompt once the script will be done. You may choose to not include it at the end of your batch file.

Now, you can see how we cd to the directory where the script is located. Then, we just have to replicate how we would launch the script from our Command prompt. As you can see, we can also include arguments the same way we would when calling a script from the shell.

One of the thing that has to be taken into account is that the Batch file will launch the console from the folder the .bat file will be saved in. Meaning if you put your .bat file in your Desktop, you will not be able to reach scripts that are located in folders that are located one folder up unless you plan for that inside of your bat file (By using cd.. etc.)

Once all of this is set up, we want to save our file with the .bat extension. In my case, I decided to name my file launch_likes.bat. This will create an executable file that will cause our computer to run the tasks described inside it when activated.

And this is pretty much all you need to know for Windows. You can now double click on your file and watch the console go by itself fetch your script and launch it without you having to mess around the Command prompt.

For Mac:

The method we’re gonna use for us Mac users follows the same concept as the way described above for Windows. The goal is to create an executable file that we then will be able to double click on.

To do so, let’s open our favorite text editor and input these lines :

As you can see, the only thing required is the full path of the script followed by the arguments if required. Don’t forget to precede this filepath with the mention “Python”. Also, the first line has to be exactly like it is shown in the code snippet above this paragraph.

When saving your file, make sure no file extension is specified.

Then, copy the filepath of this newly created file into your clipboard and launch your Terminal.

The next thing we want to do is write “chmod 755”, paste the path name previously copied in our clipboard and execute this command.

Convert Python Scripts to executable applications for Mac and Windows (2)

This will convert our extensionless file into a Unix executable that you will be able to double click on to launch your script. You could already stop at that step but for organization purposes and in order to schedule the scripts in the next article, there is still a couple of steps left to do. If you were just looking for an easy way to run your script by double-clicking on a file, you don’t need to go further 🙂

Finally, if you want a real application file instead of a simple Unix executable that you will be able to schedule, we can do so by launching Automator.

After launching the program, choose to create an “Application”.

Convert Python Scripts to executable applications for Mac and Windows (3)

In the list of actions on the left side, get the parameter “Get Specified Finder Items”. Once you added it to your right panel in Automator, you should be able to “Add” an item to this action. At this point, you want to browse through your files and select your Unix Executable.

After that, we need to add a new action, namely “Open Finder Items”. This will trigger to open the file selected previously in its default application.

Convert Python Scripts to executable applications for Mac and Windows (4)

All that’s left is to save. Choose a name that you will recognize and you will now have your own .app file ready to be launched!

Convert Python Scripts to executable applications for Mac and Windows (5)

And this wraps up our tutorial for the Mac users. I hope this is gonna allow you to spend less time on launching your scripts and more time on creating new ones.

Considering that I know how easy it is to forget to launch a script, especially if you have to do it every day, the next article is covering how to schedule these newly created executable files so that our operating systems will take care of launching those following a set schedule.

Thank you for your time 🙂

17 Responses

  1. Pingback: How to Automate Pinterest Interactions with Python

  2. What is neonphotography standing for?

    Reply

    1. Hi Koray, sorry for the delay! Thank you for reaching out to the comments section!

      “neonphotography” is an argument that my script required. This way I could use the same script but use a custom variable for each one of them 🙂 You can do the same by using the library sys and the function sys.argv! Feel free to look it up 🙂 I find it extremely useful to use python scripts in a command-line environment.

      Reply

  3. Hi Yaniss, thank you for your well-explained tutorial. Just discovered your web and it looks pretty neat. Congrats!

    Yaniss, for a strange reason, when clicking on the executable my terminal just opens and shows the following:

    “””
    Gisaels-MacBook-Pro:~ g4$ /Users/g4/Documents/Python\ for\ Automation/Exercise\ Files/OrganizeMe/createApp ; exit;
    logout
    Saving session…
    …saving history…truncating history files…
    …completed.

    [Process completed]
    “””

    But it is not running my python script. I double-checked my python script and I believe I did it right.

    “””
    #!/bin/sh
    python3 /Users/g4/Documents/Python\ for\ Automation/Exercise\ Files/OrganizeMe/organize.py
    “””

    That path is correct, I run the same exact path on my terminal and execute that script correctly. What may be happening?

    Could it be that I need to update this part? “#!/bin/sh” ? maybe my python interpreter or bash is installed on that different path? I have no idea what to do.

    Thanks!

    Reply

    1. Mine is doing the exact same thing. I cannot figure out why it won’t run the script successfully.

      Reply

    2. Bro use Python3 instead of Python… and i didn’t used neonphotography too and my code is perfectly working…

      Reply

      1. Hey Gaurav,

        Yes, as I mentioned in my article, the “neonphotography” part of the script is a sys argument that is getting retrieved from my script. You do not need an argument if your script does not take one.

        Reply

  4. The only tutorial of all internet that works to my! Thanks!
    Are there a method to hide the terminal when I execute the file.app? The terminal looks ugly on the screen.

    Reply

    1. Any ideas to hide the terminal. I would love to bring GUI app alone.

      Reply

  5. This was really helpful, thanks.

    Reply

  6. Thanks for the tutorial. When I tried using this method to run the script on my mac, I got an ImportError for modules I needed to import.
    ImportError: No module named requests
    Is there a way to by-pass this?

    Reply

    1. Hello mate! Thank you for your kind words 🙂

      So it weirdly looks like your environment does not have requests as part of its set of libraries. Could you quickly run “sudo pip install requests” in your Terminal? Or try this one as well “python -m pip install requests”

      Reply

  7. I’m getting this error

    macbook@Macbooks-MacBook-Pro ~ % /Users/macbook/Documents/Python\ projects/Stock\ trackers/hi ; exit;
    /Users/macbook/Documents/Python projects/Stock trackers/hi: line 2: /Users/macbook/Documents/Python projects/Stock trackers/Catan Resource Tracker copy 2.py: Permission denied

    Reply

    1. Any solutions?

      Reply

    2. Also, this is what my file looks like:
      #!/bin/sh
      /Users/macbook/Documents/Python\ projects/Stock\ trackers/Catan\ Resource\ Tracker\ copy\ 2.py

      Reply

  8. On Mac, just use pyinstaller (pip install pyinstaller). You run:

    pyinstaller –windowed [path to mypythonfile.py]

    in terminal and it will build a standalone app without jumping through any hoops. Replace [path to mypythonfile.py] with your specific path, no brackets.

    Reply

  9. I’m using a mac computer, but how do I convert my python codes to a desktop application to be used on windows please help.

    Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Convert Python Scripts to executable applications for Mac and Windows (2024)

FAQs

How do I make a Python program executable on a Mac? ›

Make a file executable in Terminal on Mac
  1. In the Terminal app on your Mac, use the cd command to move into the directory that contains the file you want to make executable. For example: % cd YourScriptDirectory.
  2. Enter the chmod command. For example: % chmod 755 YourScriptName.sh.

How do I convert Python scripts to Windows executable? ›

Create Executable of Python Script using PyInstaller
  1. Step 1: Add Python to Windows Path. To start, you may want to add Python to Windows path. ...
  2. Step 2: Install the PyInstaller Package. ...
  3. Step 3: Save your Python Script. ...
  4. Step 4: Create the Executable using PyInstaller. ...
  5. Step 5: Run the Executable.
25 Jun 2022

Can you convert Python script to exe? ›

In order to more easily run Python scripts on Windows machines, you can convert Python to .exe files using either cx_freeze or PyInstaller.

How to convert Python code into application? ›

One approach you can take is, use a framework like flask , Django , and host it. Save this answer. Show activity on this post. There may be multiple answers for this, but one answer would be to use Auto-Py-To-Exe to convert python code to executables, which can be ran standalone in Windows.

Can Mac execute exe files? ›

This type of file is compatible with operating systems like MS-DOS, ReactOS, Windows and OpenVMS. Since Mac computers use a different operating system than Windows computers, EXE files aren't compatible with Mac devices.

Does PyInstaller exe work on Mac? ›

PyInstaller supports making executables for Windows, Linux, and macOS, but it cannot cross compile. Therefore, you cannot make an executable targeting one Operating System from another Operating System. So, to distribute executables for multiple types of OS, you'll need a build machine for each supported OS.

How do I make a Python script executable from anywhere? ›

Making a Python script executable and runnable from anywhere
  1. Add this line as the first line in the script: #!/usr/bin/env python3.
  2. At the unix command prompt, type the following to make myscript.py executable: $ chmod +x myscript.py.
  3. Move myscript.py into your bin directory, and it will be runnable from anywhere.

How to convert Python file to exe online? ›

  1. select folder for py2exe.
  2. output for py2exe.
  3. creating exe from python file using the auto-py-to-exe selecting path.
  4. make exe from python file using auto-py-t-exe final output.
  5. select python file for creating exe from python using cx_Freeze.
  6. output for creating python script to exe using cx_Freeze.
22 Jul 2022

How do I change a script to exe? ›

Steps to write and execute a script
  1. Open the terminal. Go to the directory where you want to create your script.
  2. Create a file with . sh extension.
  3. Write the script in the file using an editor.
  4. Make the script executable with command chmod +x <fileName>.
  5. Run the script using ./<fileName>.

What is the difference between Python exe and py exe? ›

This basically put the path to that version inside the PATH, so that the executable is directly available. py is the Python launcher which is a utility that comes with Python installations on Windows. It gets installed into C:\Windows\ so it's available without requiring PATH modifications.

Do I need Python installed to run a Python executable? ›

py2exe is a Python extension which converts Python scripts (. py) into Microsoft Windows executables (.exe). These executables can run on a system without Python installed. It is the most common tool for doing so.

How do I deploy a Python application in Windows? ›

Let us know.
  1. Go to the application folder: Console Copy. cd msdocs-python-django-webapp-quickstart.
  2. Create a virtual environment for the app: Windows. macOS/Linux. Cmd Copy. ...
  3. Install the dependencies: Console Copy. pip install -r requirements.txt.
  4. Run the app: Console Copy. python manage.py runserver.
8 Nov 2022

Can I create applications using Python? ›

Python is an open-source programming language that is great for creating web and mobile apps. Applications like Instagram and Dropbox are built using Python.

Can Python make desktop applications? ›

Kivy is a cross-platform Python software development framework. With it, you can create Desktop applications for Windows, OS X, and Linux, build mobile apps for iOS and Android, and use it on embedded devices on top of Raspberry Pi. You've read it correctly. Python is no longer limited to web and desktop development.

Can Python scripting be used for application development? ›

Python is a general-purpose language, which means it's designed to be used in a range of applications, including data science, software and web development, automation, and generally getting stuff done.

What is EXE file called on Mac? ›

The EXE file extension is common, but it is specific to executable files on Windows. Mac executable files have the APP extension.

Can m1 run exe files on Mac? ›

Can My Mac Run Windows EXE? No, you cannot run Windows EXE files without some help. However, with a translator or a compatible installation of Windows, you can get a Windows EXE file working on your Mac.

What do Macs use instead of exe? ›

Apple Mac OS X does not use Executable files (.exe). Those are for Windows based computers. Mac OS X uses . DMG files and .

What is better than PyInstaller? ›

Nuitka. Nuitka is a Python compiler written in Python. It's fully compatible with Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, and 3.10. You feed it your Python app, it does a lot of clever things, and spits out an executable or extension module.

Does Mac have an FTP client? ›

Mac computers have a built-in FTP server which users can easily use to allow others access to specific files and documents.

Is there an alternative to PyInstaller? ›

There are five alternatives to PyInstaller for Windows, Linux and Mac. The best alternative is nuitka, which is both free and Open Source. Other great apps like PyInstaller are py2exe, cx_Freeze, Shed Skin and bbfreeze.

Can I run a Python script without terminal? ›

You are now able to run Python scripts from:

The operating system command-line or terminal. The Python interactive mode. The IDE or text editor you like best. The file manager of your system, by double-clicking on the icon of your script.

How do I get the Python executable path? ›

Press Start in the lower left corner of your display; press Search; in the search window, press all files and folders; in the top textline that appears, type python.exe; press the Search button. After several minutes, the folder where Python is installed will be listed --- that folder name is the path to Python.

Can convert Python script to APK? ›

  • STEP 1: Use these pre-written commands. Open this colab notebook, and you will find some prewritten commands. ...
  • STEP 2: Import your . py file (and assets you used in your app) ...
  • STEP 3: Run the “! buildozer” init command. ...
  • STEP 4: Making sure your app doesn't crash!! ...
  • STEP 5: Execute “!
1 Oct 2021

How to create an executable file? ›

To create an executable, create an Application document (. gcomp), add source files to the document, and build the application into an executable.
...
Creating an Executable
  1. Click File » New » Application.
  2. In the Create Application dialog box, enter values in Application name and Namespace.
  3. Click OK.
22 Mar 2022

How to compile a Python code? ›

Python compile()
  1. compile() Syntax. The syntax of compile() is: compile(source, filename, mode)
  2. compile() Parameters. The compile() method takes in the following parameters: ...
  3. compile() Return Value. The compile() method returns.
  4. Example: Python compile()

Can a batch file be converted to exe? ›

Next, launch the Bat To Exe Converter and click on the Open toolbar button at the window's top-left corner, and locate the batch file you want to convert (HelloWorld. bat). 3. Click on Convert to provide a name and target location for the EXE file, then click Save to convert your batch file to an EXE file.

Can exe files run scripts on your computer? ›

Exe File? An executable file is a type of computer file that runs a program when it is opened. This means it executes code or a series of instructions contained in the file. The two primary types of executable files are 1) compiled programs and 2) scripts.

Is exe the same as DLL? ›

Both of these include executable code, however, DLL and EXE operate differently from one another. The EXE will create its own thread and reserve resources for it if you run it. A DLL file, on the other hand, is an in-process server, so you cannot run a DLL file on its own.

Is py faster than Java? ›

Java and Python are two of the most popular programming languages. Of the two, Java is the faster language, but Python is simpler and easier to learn. Each is well-established, platform-independent, and part of a large, supportive community.

Where is Python exe on Mac? ›

The Apple-provided build of Python is installed in /System/Library/Frameworks/Python. framework and /usr/bin/python , respectively.

How to make your Python script run everywhere without Python? ›

How to run python files without typing python and extension (in Linux)
  1. Step 1 : Add shebang line as first line in your python code. #!/usr/bin/python3. ...
  2. Step 2 : Make your python file executable. ...
  3. Step 3 : Move your file to bin to run it from anywhere.

How do I install Python executable installer? ›

Step 1: Download the Python Installer binaries
  1. Open the official Python website in your web browser. Navigate to the Downloads tab for Windows.
  2. Choose the latest Python 3 release. ...
  3. Click on the link to download Windows x86 executable installer if you are using a 32-bit installer.
3 Aug 2022

Can Python run without compiler? ›

Python does not need a compiler because it relies on an application (called an interpreter) that compiles and runs the code without storing the machine code being created in a form that you can easily access or distribute.

Which one is better Django or Flask? ›

As a full-stack web framework, Django is best suited for developing large and complex web applications, while Flask is a lightweight, extensible framework that allows you to develop small web applications.

How to convert code into software? ›

A compiler takes the program code (source code) and converts the source code to a machine language module (called an object file). Another specialized program, called a linker, combines this object file with other previously compiled object files (in particular run-time modules) to create an executable file.

Can Python app run on Windows? ›

To install Python using the Microsoft Store: Go to your Start menu (lower left Windows icon), type "Microsoft Store", select the link to open the store. Once the store is open, select Search from the upper-right menu and enter "Python". Select which version of Python you would like to use from the results under Apps.

Can you build iOS apps with Python? ›

Yes, it is possible to build iPhone apps using Python. PyMob™ is a technology which allows developers to create Python-based mobile apps where the app specific python code is compiled via a compiler tool and converts them into native source codes for each platform like iOS (Objective C) and Android(Java).

Which coding language is best for app development? ›

Java, Python, C++, Kotlin, and Rust are popular app development languages ranked among the world's top 10 most preferred languages in 2022.

How much does it cost to build a Python application? ›

A number of tech experts are usually involved in the development of a single Python web app, including front-end designers, back-end programmers, testers, or quality assurance individuals. Typically, a web development company will put a price quote of $3000-$30,000 for developing a Python web application.

Can Python make Mac apps? ›

py2app is a Python setuptools command which will allow you to make standalone application bundles and plugins from Python scripts. py2app is similar in purpose and design to py2exe for Windows. Py2app must be run on macOS and cannot be used to cross build macOS applications on Windows or Linux.

What is best GUI for Python? ›

10 Best Python Libraries for GUI
  • PyQt5.
  • Tkinter.
  • Kivy.
  • PySimpleGUI.
  • Libavg.
  • PyForms.
  • PySide2.
  • Wax.
8 Jul 2022

Why Python is not used for app development? ›

In conclusion, Python is not used for mobile development because of speed. Since mobile phones have limited memory and processing capability, they need apps designed in a framework that's fast to provide smooth functionality. Since Java is faster than Python it's used in mobile development.

Is Python or JavaScript better for app development? ›

Web apps built with JavaScript code better, work faster, and manage a pile of data, whereas Python web development takes longer to respond. JavaScript excels in this field due to the asynchronous programming nature of the best Node. js frameworks that offer high-end scalability to the apps.

Is Python a good choice for creating and executing tests for applications? ›

Thus, to be highly productive and provide great value, testers should develop coding skills to take advantage of automation. As an easy-to-learn scripting language, Python is a great choice for testers.

How do I run a Python script in App Engine? ›

Getting started with App Engine (Python 3)
  1. Overview.
  2. Setup and requirements.
  3. Write the web app.
  4. Define the dependencies.
  5. Configure the deployment.
  6. Deploy the web app.
  7. Test the web app.
  8. Update the web app.
23 Sept 2022

Where is Python executable on Mac? ›

Built-in Interpreters
  1. /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 : the Python 2.7 interpreter. Almost all Macs have this interpreter, its alias is located in /usr/bin/python.
  2. /Library/Developer/CommandLineTools/Library/Frameworks/Python3. ...
  3. /Applications/Xcode.
5 Oct 2020

How do I make a Python path executable? ›

The complete path of python.exe can be added by:
  1. Right-clicking This PC and going to Properties.
  2. Clicking on the Advanced system settings in the menu on the left.
  3. Clicking on the Environment Variables button o​n the bottom right.
  4. In the System variables section, selecting the Path variable and clicking on Edit.

How do I run a Python file on Mac command line? ›

On a Mac system, it is very straight-forward. All you need to do is open Launchpad and search for Terminal , and in the terminal, type Python and boom, it will give you an output with the Python version.

Can Python apps run on Mac? ›

Python comes pre-installed on Mac OS X so it is easy to start using. However, to take advantage of the latest versions of Python, you will need to download and install newer versions alongside the system ones.

What is Python executable? ›

The one executable file contains an embedded archive of all the Python modules used by your script, as well as compressed copies of any non-Python support files (e.g. . so files). The bootloader uncompresses the support files and writes copies into the the temporary folder. This can take a little time.

Where is Python executable installed? ›

py installed location is C:\Windows\py.exe if installed for all users, otherwise can be found at C:\Users\username\AppData\Local\Programs\Python\Launcher .

How do I create an executable path? ›

Windows CLI #
  1. Get familiar with Windows Environment Variables in Command Prompt.
  2. Open Command Prompt.
  3. Create folder C:\bin by running mkdir C:\bin.
  4. Save the binary.exe to folder C:\bin.
  5. Edit the PATH for your account setx PATH "C:\bin;%PATH%"
  6. Restart Command Prompt.
23 Jun 2021

How do I run Python exe as administrator? ›

Show activity on this post.
  1. make a batch file.
  2. add python.exe "(your py file here)" with the quotation marks.
  3. save the batch file.
  4. right click, then click run as administrator.

Can I use CMD for Python? ›

While installing Python, one IDE named IDLE is also installed. Using the IDLE we can write and also run our programs. But we can also run python programs on CMD or command prompt as CMD is the default command-line interpreter on Windows.

How do I run a script on a Mac? ›

In the Script Editor app on your Mac, click the Run button in the toolbar, or press Command-R, to execute the commands in your script.

How do I compile and run Python in CMD? ›

To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World! If everything works okay, after you press Enter , you'll see the phrase Hello World!

Top Articles
Latest Posts
Article information

Author: Greg O'Connell

Last Updated:

Views: 5739

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Greg O'Connell

Birthday: 1992-01-10

Address: Suite 517 2436 Jefferey Pass, Shanitaside, UT 27519

Phone: +2614651609714

Job: Education Developer

Hobby: Cooking, Gambling, Pottery, Shooting, Baseball, Singing, Snowboarding

Introduction: My name is Greg O'Connell, I am a delightful, colorful, talented, kind, lively, modern, tender person who loves writing and wants to share my knowledge and understanding with you.