Creatin an .exe file to run a Python script

We will be using as example the script from the following post:
https://www.jaimedcsilva.com/hello-world/calculating-displaying-crypto-currency-with-coingecko/

It was added by the end of the script a time.sleep(5) so that the console stays open for 5 seconds when we click the .exe file.
 

pip install pyinstaller==5.13.2

 

import requests
import time

def get_crypto_prices(cryptos, currency='eur'):
    crypto_ids = ','.join(cryptos)
    url = f'https://api.coingecko.com/api/v3/simple/price?ids={crypto_ids}&vs_currencies={currency}'
    
    try:
        response = requests.get(url)
        response.raise_for_status() 
        data = response.json()
        return {crypto: data[crypto][currency] for crypto in cryptos}
    
    except requests.RequestException as e:
        print(f"Error: {e}")
        return None



currency = 'eur'

quantities = {
    'bitcoin': 0.00114522,
    'ripple': 319.33343233,  
    'stellar': 449.44127517  
}

cryptos = list(quantities.keys())
prices = get_crypto_prices(cryptos, currency)

if prices:
    total_value = 0
    for crypto, amount in quantities.items():
        price = prices[crypto]
        value = amount * price
        total_value += value
        print(f"{amount} {crypto.capitalize()} worth {value:.2f} {currency.upper()}.")
    
    print(f"Total: {total_value:.2f} {currency.upper()}.")

time.sleep(5)


In the same folder, have the following files:

  • crypto.py
  • logo.ico (optional)

Change the directory in your command line to the crypto.py directory
 

pyinstaller --onefile --icon=logo.ico crypto.py

 

Pyinstaller will generate 2 folders and one file.
The .exe file is inside the dist folder.
If you ran pyinstaller without the icon and try to run it again,
it probably will not apply the icon anymore unless you change the Python script name, for example to crypto2.py, 
Windows seems to cache the icon for the same name.
The crypto.py file will not be necessary anymore. You can delete it.


pyinstaller==5.13.2



06 Jan. 2025 | Last Updated: 03 Dec. 2025 | jaimedcsilva

Related
  • Printing CMD with colors
  • Calculating & Displaying crypto currency with CoinGecko
  • Creatin an .exe file to run a Python script
  • Getting certificate chains from websites
  • Getting the complete trustchain of a website
  • Installing pip in embedded Python - Full Guide
  • Cython - Hiding Python Code
  • How to Send Emails with Python’s smtplib
  • Generating QR Codes with Python

  • Buy Me a Coffee