微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Pyinstaller 独立

如何解决Pyinstaller 独立

我正在使用 pyinstaller 将脚本转换为 exe 文件,以便我可以将其提供给没有安装 python 和其他软件包的人。它只是一个简单的脚本,它使用 pandas 和 numpy 来操作 Excel 表格。我发现我可以使用基础 conda env 运行 exe,但不能在它之外运行。我已按照在 PyInstaller .exe file terminates early without an error message 找到的修复程序进行操作,但问题仍然存在。我不知道你们需要我提供什么来帮助回答这个问题,所以请告诉我,我会编辑此条目。

我的代码

import pandas as pd
import numpy as np
import openpyxl

print('Starting Operations')

#Load the file
spend_report = pd.read_excel('Spend Report_Console.xlsx',converters={'Document\nCompany': str,'Document\nNumber':str})
print('Data Loaded')


#Load the exchange rate file
fx_rates = pd.read_excel('FX_Rates.xlsx')
#Create a new index for the dataframe. This will allow much faster accessing of the data
fx_rates['index'] = fx_rates['Date'].dt.strftime('%b-%y')
fx_rates.index=fx_rates['index']
fx_rates.drop(['Date','index'],axis=1,inplace=True)
print('FX Rates Loaded')


company_currency = {'00002':'EUR','00003':'EUR','00004':'GBP','00005':'CRC','00006':'RMB','00008':'RMB'}
# If 00001,keep the same


#Drop any row where the supplier\nNumber does not start with a number
#Make a new column,that indicates this
spend_report['to_keep'] = spend_report['supplier\nNumber'].apply(lambda x: x[0].isdigit())
spend_report.drop(spend_report[spend_report['to_keep']==False].index,axis=0,inplace=True)
spend_report.drop(['to_keep'],inplace=True)

#FillNA's in Purchase Order and Order Type
spend_report.fillna({'Purchase Order':'','Order Type':''},inplace=True)


#Correct Document Company
#Logic:
# If Document Company is 00000:
    # Replace with f'0000{First number of Document Number}'
def fix_docCompany(company,number):
    if company == '00000':
        return f'0000{number[0]}'
    return company  

spend_report['Document\nCompany'] = spend_report.apply(lambda row: fix_docCompany(row['Document\nCompany'],row['Document\nNumber']),axis=1)
print('Fixing Document Company')


#Correct the currency
#Logic:
# If company is not 00001:
    # Get value from company_currency
# return same value
def fix_currency(company,currency):
    if company != '00001':
        return company_currency[company]
    return currency

spend_report['Currency'] = spend_report.apply(lambda row: fix_currency(row['Document\nCompany'],row['Currency']),axis=1)
print('Fixing Currency')


#Check for missing currency
currencies = pd.unique(spend_report['Currency'])
missing = [curr for curr in currencies if curr not in fx_rates.columns]
if len(missing) > 0:
    print(f'The following currencies are missing:\n{missing}\nThere will be an error thrown.')
    t = input('Press enter to ackNowledge.')

# Calculate the USD amount
def usd_amount(date,currency,amount):
    return amount / fx_rates.loc[date,currency]

spend_report['USD Amount'] = spend_report.apply(lambda row: usd_amount(row['GL Date'].strftime('%b-%y'),row['Currency'],row['Gross\nAmount']),axis=1)
print('Calculating USD Amount')


#Create the PO/NON-PO column
spend_report['PO/NON-PO']=np.where(spend_report['Purchase Order']=='','NON-PO','PO')
print('Creating PO/NON-PO Column')


#Write to excel after rearranging columns
print('Writing to Excel')
with pd.ExcelWriter(f'Spend Report_Output.xlsx',datetime_format='m/dd/yyyy',engine='openpyxl') as writer:
    spend_report[['supplier\nNumber','Document\nType','Document\nNumber','Document\nCompany','Pay Item','Invoice Date','GL Date','Due Date','Pay\nStatus','Gross\nAmount','Open\nAmount','Currency','USD Amount','Batch\nType','Batch\nNumber','Batch\nDate','Purchase Order','Order Type','PO/NON-PO']].to_excel(writer,sheet_name='SpendReport',index=False)
    fx_rates.to_excel(writer,sheet_name='FX_Rate')

print('Operations Complete')

我的 Conda Env 是使用以下命令创建的:

conda create -n make python=3.9
conda activate make
conda install numpy
conda install pandas
conda install openpyxl
conda install pyinstaller

我不得不修改规范文件,因为我遇到了英特尔 MKL 致命错误问题。 我使用函数创建了文件

pyinstaller -F Spend_Report.spec

当我在 (base) 和 (make) 环境中运行它时,它工作正常。

(base) C:\Users\**\**\Spend Report>Spend_Report.exe
Starting Operations
Data Loaded
FX Rates Loaded
Fixing Document Company
Fixing Currency
Calculating USD Amount
Creating PO/NON-PO Column
Writing to Excel
Operations Complete
(make) C:\Users\**\**\Spend Report>Spend_Report.exe
Starting Operations
Data Loaded
FX Rates Loaded
Fixing Document Company
Fixing Currency
Calculating USD Amount
Creating PO/NON-PO Column
Writing to Excel
Operations Complete

但是,如果我关闭 conda 命令提示符,则会打开常规的 Windows 命令提示符。 exe 不起作用,只是挂起。我需要帮助,因为我会将它发送给从未编码过的人。他们的计算机上不会安装 anaconda 或 python。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。