0

I wrote a simple capital city quiz in python then complied it using pyinstaller and it is over 300MB! The code is below. Any ideas as to why it is so large!

Cheers,

Rich

import pandas as pd
from random import shuffle
from requests import post

difficulty=""
while difficulty.lower() != "easy" and difficulty.lower() != "hard":
    difficulty = input("Easy or Hard? ")
filename = "capitals_"+difficulty+".csv"

dataset = pd.read_csv(filename)
quiz_data = dataset.iloc[:, 0:2].astype(str).values.tolist()
shuffle(quiz_data)

name=""
while name.lower() != "beth" and name.lower() != "penny":
    name = input("Are you Beth or Penny? ")
webhooks_event=name + "Flash"




score=0
for n in range(10):
    ans=input(f"What is the capital city of {quiz_data[n][0]}? ")
    if ans.lower()==quiz_data[n][1].lower():
        print("Correct!")
        score+=1
    else:
        print(f"Sorry the correct answer was {quiz_data[n][1]}")

if score < 5:
    print(f"You need to do more studying! you got {score} out of 10!")
elif score <10:
    print(f"Well done you got {score} out of 10")
else:
    print("Excellent, you got them all right!")
    post(f"https://maker.ifttt.com/trigger/{webhooks_event}/with/key/#")
input("Press enter to continue")
frankr1977
  • 13
  • 1
  • 4
  • 4
    I guess PyInstaller has to include all the modules you use (pandas, random and requests), and all the modules they use, and all the modules they use, etc... – Ed Ward Feb 16 '20 at 19:47
  • PyInstaller has issues with pandas https://stackoverflow.com/questions/29109324/pyinstaller-and-pandas – trigonom Feb 16 '20 at 19:56
  • On the bright side, if Pandas is indeed the issue then you can quite easily rewrite the program without it. What do the contents of the CSV file look like? – AMC Feb 16 '20 at 20:04
  • Another possibly related question: https://stackoverflow.com/questions/43886822/pyinstaller-with-pandas-creates-over-500-mb-exe/48846546#48846546 – AMC Feb 16 '20 at 20:07
  • Python has a built-in CSV library (called `csv`) which will work in the vast majority of use-cases, and since it’s part of the standard library it won’t bloat your code like Pandas is. Give that a shot. requests shouldn’t be too expensive, I think, but it could also be replaced (less nicely) with urllib. – nneonneo Feb 16 '20 at 20:27
  • Thanks for the help, the data in the csv is very simple so I am sure I can use a simpler csv import method. Thanks for the help – frankr1977 Feb 16 '20 at 21:40

0 Answers0