最近,我创建了一个python脚本来读取一些excel文件,并根据这些读数创建一个新的Pandas DataFrame。我通过Pyinstaller创建了一个可执行文件(一个文件和多个文件)。如果我在解释器上运行代码,则运行得很好,如果在PC上运行可执行文件,它也可以工作,但是如果我的同事在她的计算机上运行,则会出现以下错误:
这是可执行文件引发的第二个错误。首先,我在导入“ pkg_resources.py2_warn”时遇到错误,我按照Pyinstaller指令纠正了该错误,直接在代码上导入了软件包,但是对于此错误-3我什么也找不到。
有人知道如何解决此问题吗?完整的代码如下:
###Import Libraries
import os
import pandas as pd
import pkg_resources.py2_warn
###Variables
CAO, CAO2, F24, F26, F25, F28, S48, S49, S50, S76, S77, S78, T51, T68,T79, T86, T83, multiplication, Sum_EF, Sum_EG, lst, file_list, indx = [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]
temp = pd.DataFrame()
path = r'C:\Users\Documents\Codes\test'
###Setting the file list
f_list = os.listdir(path)
for l in f_list:
try:
c = l.split('_')[1]
if c[0] != 'C':
file_list.append(l)
except: None
###Data mining
for file in file_list:
cao = int(file.split('_')[1])
file_path = os.path.join(path, file)
f = pd.read_excel(file_path, sheet_name = 'CAO - Recap', header = 21, usecols = 'F, S, T')
f24 = f.iloc[1][0]
f25 = f.iloc[2][0]
f26 = f.iloc[3][0]
f28 = f.iloc[5][0]
s48 = f.iloc[25][1]
s49 = f.iloc[26][1]
s50 = f.iloc[27][1]
s76 = f.iloc[53][1]
s77 = f.iloc[54][1]
s78 = f.iloc[55][1]
t51 = f.iloc[28][2]
t68 = f.iloc[45][2]
t79 = f.iloc[56][2]
t86 = f.iloc[63][2]
t83 = f.iloc[60][2]
mult = t86 * t83 * 0.002
CAO.append(cao)
F24.append(f24)
F25.append(f25)
F26.append(f26)
F28.append(f28)
S48.append(s48)
S49.append(s49)
S50.append(s50)
S76.append(s76)
S77.append(s77)
S78.append(s78)
T51.append(t51)
T68.append(t68)
T79.append(t79)
T83.append(t83)
T86.append(t86)
multiplication.append(mult)
###DataFrame assembly
temp['CAO'] = pd.Series(CAO)
temp['F24'] = pd.Series(F24)
temp['F25'] = pd.Series(F25)
temp['F26'] = pd.Series(F26)
temp['F28'] = pd.Series(F28)
temp['S48'] = pd.Series(S48)
temp['S49'] = pd.Series(S49)
temp['S50'] = pd.Series(S50)
temp['S76'] = pd.Series(S76)
temp['S77'] = pd.Series(S77)
temp['S78'] = pd.Series(S78)
temp['T51'] = pd.Series(T51)
temp['T68'] = pd.Series(T68)
temp['T79'] = pd.Series(T79)
temp['T83'] = pd.Series(T83)
temp['T86'] = pd.Series(T86)
temp['Multiplication'] = pd.Series(multiplication)
###Data Cleaning
temp = temp.loc[: , ~temp.columns.str.contains('^Unnamed')]
temp.reset_index()
###Data Structure auxiliary table
order = pd.DataFrame(columns = {'index', 'CAO'}) ##Ordering rows
order['CAO'] = pd.Series([2948, 533, 487, 433, 10, 1612, 301, 1496, 1869, 1944, 234, 50, 833, 496, 725, 1287, 3798, 243, 750, 748, 3768, 650, 3854, 2535, 637, 26, 51, 41, 791, 359, 35, 157, 465, 254, 214, 615, 1945, 2266, 549, 245, 83, 1537, 848, 573, 306, 279, 632, 979, 253, 1393, 475, 709, 171, 118, 125, 1029, 563, 1193, 187, 1841, 819, 841, 2674, 152, 80, 310, 1438, 227, 2872, 506, 645, 776, 85, 636, 3954, 3233, 1228, 3967, 830])
n = 1
for i in order['CAO']:
indx.append(n)
n += 1
order['index'] = pd.Series(indx)
###DataFrame preparation
Lst1 = pd.merge(order, temp, on = 'CAO', how = 'left' )
Lst1.drop_duplicates(subset = 'index', keep = 'first')
Lst1.reset_index()
Lst1 = Lst1[['CAO', 'T68', 'T86', 'T83', 'Multiplication', 'T79', 'S76', 'S77', 'S78', 'F24', 'F26', 'F25', 'F28', 'T51', 'S48', 'S49', 'S50']] ##Ordering columns 'Sum_EF', 'Sum_EG'
Lst1 = Lst1.fillna('-')
Lst1.to_csv(r'C:\Users\Documents\full_list.csv', sep = ';', decimal = ',')
感谢所有帮助!