mislav / hub

A command-line tool that makes git easier to use with GitHub.
https://hub.github.com/
MIT License
22.77k stars 2.2k forks source link

pyinstaller Problem Creating an Exe File that depends on Matplotlib #2606

Closed Ludo915 closed 4 years ago

Ludo915 commented 4 years ago

Hi,

I get a bug when I try to create an .exe file from Python Code that imports Matplotlib and works fine in Jupyter with the following command: pyinstaller --onefile Wallet12.py.

Please Help!

Here is the bug:

bug

Here is the code: ` import os import requests import datetime from datetime import date from bs4 import BeautifulSoup import pandas as pd import matplotlib.pyplot as plt from tabulate import tabulate import subprocess nbAppleStock = 189 nbMicrosoftStock = 100 AppleInit = 127.84 MicrosoftInit = 228.0599 EURUSDInit = 1.19517400 InitialWalletInvested = (nbAppleStock AppleInit + nbMicrosoftStock MicrosoftInit)/EURUSDInit fees = 0.0047 InitialWalletInvested feesApple = 0.0047 AppleInitnbAppleStock / EURUSDInit feesMicrosoft = 0.0047 MicrosoftInit*nbMicrosoftStock / EURUSDInit fees = 0 feesApple = 0 feesMicrosoft = 0

url1='https://fr.finance.yahoo.com/quote/AAPL/history/' url2='https://fr.finance.yahoo.com/quote/MSFT/history/' url3='https://fr.finance.yahoo.com/quote/EURUSD=X/' url4='https://finance.yahoo.com/quote/AAPL/history?p=AAPL' url5='https://finance.yahoo.com/quote/MSFT/history?p=MSFT' url6='https://finance.yahoo.com/quote/EURUSD%3DX/history?p=EURUSD%3DX'

page1 = requests.get(url1) page2 = requests.get(url2) page3 = requests.get(url3) page4 = requests.get(url4) page5 = requests.get(url5) page6 = requests.get(url6) soup1 = BeautifulSoup(page1.text, 'html.parser') soup2 = BeautifulSoup(page2.text, 'html.parser') soup3 = BeautifulSoup(page3.text, 'html.parser') soup4 = BeautifulSoup(page4.text, 'html.parser') soup5 = BeautifulSoup(page5.text, 'html.parser') soup6 = BeautifulSoup(page6.text, 'html.parser')

print(soup1.prettify())

AppleStockPriceString = soup1.find('div',{'class': 'My(6px) Pos(r) smartphone_Mt(6px)'}).find('span').text MicrosoftStockPriceString = soup2.find('div',{'class': 'My(6px) Pos(r) smartphone_Mt(6px)'}).find('span').text EURUSDString = soup3.find('div',{'class': 'My(6px) Pos(r) smartphone_Mt(6px)'}).find('span').text AppleStockPriceString = AppleStockPriceString.replace(",",".") MicrosoftStockPriceString = MicrosoftStockPriceString.replace(",",".") EURUSDString = EURUSDString.replace(",",".") AppleStockPrice = float(AppleStockPriceString) MicrosoftStockPrice = float(MicrosoftStockPriceString) EURUSD = float(EURUSDString) print("EURUSD: " + EURUSDString) print("AppleStockPrice: " + str(AppleStockPrice) + "$") print("MicrosoftStockPrice: " + str(MicrosoftStockPrice) + "$") EURUSDPerformance = 1/(1 + (EURUSD/EURUSDInit)-1) - 1 print("EURUSD Performance SI: " + str(round(EURUSDPerformance 100,2)) + "%") WalletPresentValue = (nbAppleStock AppleStockPrice + nbMicrosoftStock MicrosoftStockPrice)/EURUSD print("Fees: " + str(fees) + "€") Performance =(WalletPresentValue/(InitialWalletInvested + fees) - 1) print("Overall Performance SI: " + str(round((Performance)100,2)) + "%") print("Apple Performance SI: " + str(round((((1 + AppleStockPrice/(AppleInit) - 1))(1-feesApple/(nbAppleStockAppleInit))(1+EURUSDPerformance)-1)100,2))+ "%") PNLApple = round(nbAppleStock AppleInit ((1 +(AppleStockPrice/AppleInit -1))(1+ EURUSDPerformance))/EURUSDInit - nbAppleStock AppleInit/EURUSDInit - feesApple, 2) print("P&L on Apple: " + str(PNLApple) + "€") print("Microsoft Performance SI: " + str(round((((1 + MicrosoftStockPrice/(MicrosoftInit) - 1))(1-feesMicrosoft/(nbMicrosoftStockMicrosoftInit))(1+EURUSDPerformance)-1)100,2)) + "%") PNLMicrosoft = round(nbMicrosoftStock MicrosoftInit ((1 +(MicrosoftStockPrice/MicrosoftInit -1))(1+ EURUSDPerformance))/EURUSDInit - nbMicrosoftStock MicrosoftInit/EURUSDInit - feesMicrosoft, 2) print("P&L on Microsoft: " + str(PNLMicrosoft) + "€") print("P&L: " + str(round(PNLApple + PNLMicrosoft,2))) print("Invested Wallet Present Value in €: " + str(round(WalletPresentValue,2))) Cash = 11637 print("Total Compte Titres in €: " + str(round(Cash + WalletPresentValue,2)))

table = soup4.find('table') table_rows = table.find_all('tr') res = [] for tr in table_rows: td = tr.find_all('td') row = [tr.text.strip() for tr in td if tr.text.strip()] if row: res.append(row) df1 = pd.DataFrame(res, columns=["Date", "Ouverture", "Élevé ", "Faible ","Clôture","Cours de clôture ajusté","Volume"]) df1 = df1.drop(["Ouverture", "Élevé ", "Faible ","Cours de clôture ajusté","Volume"], axis=1) df1 = df1.drop_duplicates("Date", keep='first', inplace=False) df1['Clôture'] = df1['Clôture'].str.replace(',','.') df1["Clôture"] = pd.to_numeric(df1["Clôture"], downcast="float") df1["Date"] = df1["Date"].astype(str) df1["Date"].describe() indexNames = df1[ df1['Date'].str.contains("split") ].index df1.drop(indexNames , inplace=True) df1['Date'] = df1['Date'].astype('datetime64[ns]') df1.plot(figsize=(10,2), x ='Date', y='Clôture', kind = 'line') plt.title('Apple Stock Prices in $') plt.xlabel('Dates') plt.ylabel('Stock Price in $') plt.show() df1Wallet = df1[df1["Date"] >= '2020-09-01'] table = soup5.find('table') table_rows = table.find_all('tr') res = [] for tr in table_rows: td = tr.find_all('td') row = [tr.text.strip() for tr in td if tr.text.strip()] if row: res.append(row) df2 = pd.DataFrame(res, columns=["Date", "Ouverture", "Élevé ", "Faible ","Clôture","Cours de clôture ajusté","Volume"]) df2 = df2.drop(["Ouverture", "Élevé ", "Faible ","Cours de clôture ajusté","Volume"], axis=1) df2 = df2.drop_duplicates("Date", keep='first', inplace=False) df2['Clôture'] = df2['Clôture'].str.replace(',','.') df2["Clôture"] = pd.to_numeric(df2["Clôture"], downcast="float") df2["Date"] = df2["Date"].astype(str) df2["Date"].describe() indexNames = df2[ df2['Date'].str.contains("split") ].index df2.drop(indexNames , inplace=True) df2['Date'] = df2['Date'].astype('datetime64[ns]') df2.plot(figsize=(10,2), x ='Date', y='Clôture', kind = 'line') plt.title('Microsfot Stock Prices in $') plt.xlabel('Dates') plt.ylabel('Stock Price in $') plt.show() df2Wallet = df2[df2["Date"] >= '2020-09-01']

table = soup6.find('table') table_rows = table.find_all('tr') res = [] for tr in table_rows: td = tr.find_all('td') row = [tr.text.strip() for tr in td if tr.text.strip()] if row: res.append(row) df3 = pd.DataFrame(res, columns=["Date", "Ouverture", "Élevé ", "Faible ","Clôture","Cours de clôture ajusté","Volume"]) df3 = df3.drop(["Ouverture", "Élevé ", "Faible ","Cours de clôture ajusté","Volume"], axis=1) df3 = df3.drop_duplicates("Date", keep='first', inplace=False) df3['Clôture'] = df3['Clôture'].str.replace(',','.') df3['Clôture'] = df3["Clôture"].apply (pd.to_numeric, errors='coerce') df3 = df3.dropna() df3["Clôture"] = pd.to_numeric(df3["Clôture*"], downcast="float") df3["Date"] = df3["Date"].astype(str) df3["Date"].describe()

df3['Date'] = df3['Date'].astype('datetime64[ns]') df3.plot(figsize=(10,2), x ='Date', y='Clôture', kind = 'line') plt.title('EURUSD Exchange Rate') plt.xlabel('Dates') plt.ylabel('EURUSD Exchange Rate') plt.show() df3Wallet = df3[df3["Date"] >= '2020-09-01'] Wallet = pd.merge(df1Wallet, df2Wallet, on='Date') Wallet = pd.merge(Wallet, df3Wallet, on = 'Date') Wallet['Wallet'] = (Wallet["Clôture_x"]nbAppleStock + Wallet["Clôture_y"]nbMicrosoftStock)/Wallet["Clôture"] Wallet['Performance SI'] = (Wallet['Wallet']-InitialWalletInvested)/InitialWalletInvested Wallet['Date'] =pd.to_datetime(Wallet.Date) Wallet = Wallet.drop(["Clôture_x","Clôture_y","Clôture"], axis=1) Wallet = pd.concat([pd.DataFrame([[pd.to_datetime('2020-08-31'), float(InitialWalletInvested), float(0)]],columns=Wallet.columns),Wallet],ignore_index=True) Wallet = pd.concat([pd.DataFrame([[pd.to_datetime(date.today()), float(WalletPresentValue), Performance]],columns=Wallet.columns),Wallet],ignore_index=True) Wallet['Performance SI']=Wallet['Performance SI']100 Wallet = Wallet.sort_values(by='Date') Wallet.plot(figsize=(10,2), x ='Date', y='Wallet', kind = 'line')

plt.title('Ludo Wallet') plt.xlabel('Dates') plt.ylabel('Value in €') plt.show() Wallet.plot(figsize=(10,2), x ='Date', y='Performance SI', kind = 'line') plt.title('Ludo Wallet Performance SI') plt.xlabel('Dates') plt.ylabel('Performance in %') plt.show()

os.system('jupyter-nbconvert --to PDFviaHTML Wallet12.ipynb') os.system('explorer.exe "Wallet12.pdf"')

`

mislav commented 4 years ago

This issue tracker is for a command-line tool called "hub" which is written in Go. Your question seems unrelated to this project, and you should find a more appropriate forum to ask it in. Thank you.