我在.py文件上运行了pyinstaller,并且一切正常,除了一行通过subprocess命令调用另一个.py文件。这是我的.py文件的代码,其中包含子过程行:
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import PySimpleGUI as sg
import subprocess
py_file_path = "C:\\Users\\PIN CM 5\\Documents\\Python_Scripts\\Master_Script_v2.py"
gif_file_path= "C:\\Users\\PIN CM 5\\Desktop\\Bryant\\Wait Gifs\monkey.gif"
layout = [[sg.Text('Choose Report')],
[sg.Listbox(values=('Industry Review (all)', 'Kia_IP', 'Hyundai_IP', 'Mitsu_IP','Acura_IR', 'Honda_IR', 'Hyundai_IR', 'Kia_IR', 'Mazda_IR','Mitsu_IR'), size=(40, 5))],
[sg.Text('[Required] Enter report date (YYYYMM):'), sg.InputText()],
[sg.Text('Refresh Cube?'), sg.Combo(['Yes', 'No'], default_value = 'No')],
[sg.Text('Month-end or MTD?'), sg.Combo(['Month-end', 'MTD'], default_value = 'MTD')],
[sg.Text('[MTD] Enter share data through (YYYYMMDD):'), sg.InputText()],
[sg.Text('[MTD] Enter spend data through (YYYYMMDD):'), sg.InputText()],
[sg.Text('[MTD] Enter month-end forecast (no commas):'), sg.InputText()],
[sg.OK(), sg.Cancel()]]
window = sg.Window('Create Decks', layout)
while True:
event, values = window.Read()
inputs_list = ['report_name', 'report_date', 'refresh_cube', 'monthend_or_MTD', 'share_date', 'spend_date', 'forecast']
inputs_dict = {}
for i, input in enumerate(inputs_list):
if i == 0:
inputs_dict[input] = values[i][i]
elif values[i] == '':
inputs_dict[input] = "0"
else:
inputs_dict[input] = values[i]
if event is None or event == 'Exit' or event == 'Cancel':
break
else:
sg.PopupAnimated(gif_file_path, message='Just a sec...', background_color='#FFF', font=("Helvetica",18), keep_on_top=True)
subprocess.call(['python', py_file_path , inputs_dict['report_name'], inputs_dict['report_date'], inputs_dict['refresh_cube'], inputs_dict['monthend_or_MTD'], inputs_dict['share_date'], inputs_dict['spend_date'], inputs_dict['forecast']])
sg.PopupAnimated(image_source=None)
sg.Popup("Complete.\nPlease go to Desktop -> Monthly Automation -> Output", keep_on_top=True)
window.Close()
# In[ ]:
我在命令提示符下运行了它,并且执行得很好:
python "C:\\Users\\PIN CM 5\\Documents\\Python_Scripts\\Master_Script_v2.py" Kia_IP 201909 No Month-end 0 0 0
在我将程序迁移到新计算机后出现了这个问题(旧的计算机具有用户“ PIN”,而新的计算机是“ PIN CM 5”,但是添加引号应该可以解决该问题)。谢谢您的帮助。