[Python] Need Help Converting a Set of Python Scripts Into an App [closed]

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have a set of python scripts + other files that I need to build into an application. The python scripts include 2 separate processes and the other files include .json, .txt and a .xlsm file. (Note: The two processes are separate and cannot call each other by themselves)

    The first python process is to call the .xlsm file however, when I built the app using pyinstaller, the code is unable to find the .xlsm file.

    The second python process is called upon by clicking a specific cell in the .xlsm file (done so by adding macros), however in this case, the .xlsm file cannot find the python scripts.

    For the first process to find the excel script, I had written this in the first python process's script

    script_directory = os.path.dirname(os.path.abspath(__file__))
    output_file_path = os.path.join(script_directory, "ExcelFile.xlsm")


    And for the excel file to access the second python process's script I had written this in VBA:

    Sub RunPythonScript()
    Dim objShell As Object
    Set objShell = CreateObject("WScript.Shell")
    Dim scriptPath As String
    scriptPath = ThisWorkbook.Path & "\python_script.py"
    'MsgBox "Command: " & "pythonExe """ & scriptPath & """"
    objShell.Run "cmd.exe /c python """ & scriptPath & """", vbHide
    Set objShell = Nothing
    End Sub


    This function was correctly called when a specific cell was clicked in the excel file.

    Then when I built the app with the excel, python, etc files inside, the first python process was able call the excel file but when clicking that certain cell, the excel registered the click but was not able to find/call the python script for the second process.

    So I tried another approach: I built the app without the excel file and the script for the second process. In this case I put the app (.exe), the excel (.xlsm) and the python scripts for the second process all in a folder (that I could then compress to distribute). When I ran the app, it was unable to find the excel file. And (of course) when I opened the excel file manually, it was able to run the second python process.

    Please suggest a solution for this such that the python scripts for the first process(includes about 10-12 modules) can access the excel file and the VBA code in the excel can access the python scripts for the second process.

    Continue reading...

Compartilhe esta Página