In this tutorial, I show you how to create a standalone Windows executable file from a Python script using PyCharm Community Edition. The process involves setting up a new project named ‘converter’, which includes creating a new virtual environment. Once the environment is ready, I proceed to write our script in a file named ‘converter.py’.

The application’s functionality is to convert currencies using an API call. To facilitate the API interaction, I import the ‘requests’ package (which we install in our project environment) and the ‘os’ package. An API key is required to access the currency conversion service, which I have stored as an environment variable on my machine.

I code the script to prompt the user for the currency codes they are converting from and to, without error checking for simplicity. The script constructs a JSON object for the query string, using the currency codes provided by the user. I then configure the request headers, including my API key and the RapidAPI host, and make the API call, storing the response in a variable.

After verifying a successful response with a status code of 200, I print the conversion results. If there’s an error, an appropriate message is displayed. I test the script with a currency conversion from EUR to USD and receive the correct conversion rate.

To convert the script into an executable, I use PyInstaller with the ‘–onefile’ option to package all dependencies into a single file. After running PyInstaller, I navigate to the ‘dist’ folder where the ‘converter.exe’ file is located. Testing the executable, I input USD to EUR and confirm it provides the correct conversion, showing the versatility of the script in executable form.