Command-Line Utility: Part 2 - How to get rid of the ".py" extension
Tags: python, cli, python3, windows
Published: 2021-04-09 10:29:06

---
title: Command-Line Utility: Part 2 - How to get rid of the ".py" extension
published: true
series: Python CLI
date: 2021-02-10 12:47:01 UTC
tags: Python,cli,Python3,Windows
canonical_url: https://pybash.hashnode.dev/command-line-utility-part-2
---

## Introduction

This post is a continuation of the previous post "How to make a Command-Line Utility in Python". If you have not seen it yet, [click here](https://play4tutorials.hashnode.dev/how-to-create-a-command-line-utility-using-python).

## Prerequisites

Alright, so we are going to be needing a few modules and tools for this. First, we need [`pyinstaller`](https://pypi.org/project/pyinstaller/) and second, we need [`auto-py-to-exe`](https://pypi.org/project/auto-py-to-exe/)

## Explanation

On [Windows](https://windows.com)(not sponsored by Microsoft), if you want to access the file without the ".py" extension, we need to convert it to an executable or ".exe" file. So we are going to be using these two tools to make it an executable. `pyinstaller` is pretty popular, and I am sure a lot of you already know about it. And how to use it.

## Installation

### [`pyinstaller`](https://pypi.org/project/pyinstaller/)

#### Official Way

Steps:

1. Click on Start
2. Type "Command Prompt" and click Enter on your Keyboard
3. A new command prompt window should open
4. Now, type `pip install pyinstaller`
5. And done!

* * *

#### [Unofficial Way](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyinstaller)

**Warning! - This is not the official pyinstaller wheel. Only use this if for some reason the official way fails.** Steps:

1. Go to [ifd.uci.edu/~gohlke/pythonlibs/#pyinstaller](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyinstaller)
2. The first link at the top of the page, is to be downloaded. The name of the file is `pyinstaller-4.2-py3-none-any.whl`. This is only for Python3.
3. Download the file and save it on the Desktop
4. Then, click on start
5. Type "Command Prompt" and click Enter on you keyboard.
6. A new command prompt window should open
7. Now type the following commands:
```
C:\Users\[username]> cd Desktop
C:\Users\[username]\Desktop> pip install pyinstaller-4.2-py3-none-any.whl
A lot of text keeps on scrolling and then shows, successfully installed pyinstaller

```
8. And done!

* * *

### [`auto-py-to-exe`](https://pypi.org/project/auto-py-to-exe/)

Steps:

1. Click on Start
2. Type "Command Prompt" and click Enter on your Keyboard
3. A new Command Prompt Window should open
4. Now, type `pip install auto-py-to-exe`
5. And done!

## Converting to `exe`

Steps:

1. Open windows explorer and navigate to the folder where you have your CLU(Command-Line Utility) file stored.
2. Now open another Command Prompt window
3. And, type `auto-py-to-exe`
4. A new window should pop-up as given below ![auto-py-to-exe_window_image](https://cdn.hashnode.com/res/hashnode/image/upload/v1612958295841/3Y45lbhM-.png)
5. Now, copy the path to the file from the explorer and paste it in the Script Location box. For e.g., - D:\Programming\CLI-Utilities\search.py If the path is correct, the border should turn to red from blue
6. Then, select One File and Console Based
7. Then expand Settings
8. Under output folder, enter the folder path where, the `.py` file is located For e.g., - D:\Programming\CLI-Utilities Refer to the above image
9. And then, click on "CONVERT PY TO EXE" button, And a lot of output will be shown.
10. Then go to the directory where the script is located and an `exe` named `search.exe` should be there.
11. Now, go back to the Command Prompt
12. Now type, only `search` and pass the arguments and it will work like a charm!

## Conclusion

Maybe, you will be wondering, why can't we just rename the file to `search` from `search.py` and it should work, just like in Unix right? No, windows does not work like that! If you did that and typed search, then windows would simply search the `PATH` variable for an `exe` named "search", and since it won't find any, it would just say, that Not Found... So we need to convert it to an `exe` to work as intended.