05-12-2025 01:07 PM
Hello,
I'm using LabVIEW 2021 SP1.
I'm using the Python node to call Python functions from a main Python script (.py).
I have a Python SDK in a separate folder. I have the main Python script in the same folder as the LabVIEW project. The main Python script defines the absolute path to the SDK using:
os.path.append
The folder structure is something like this:
C:\Project\LabVIEW Source code
C:Project\Main Python Script
C:\Project\Python SDK\.py files
I have checked all the module names and paths. Everything is correct. I can successfully run a Python script using the same folder structure calling the same Python functions.
The LabVIEW source code also works perfectly. But the application (.exe) throws a 'ModuleNotFoundError'.
Solved! Go to Solution.
05-13-2025 07:07 AM
Did you use probes or indicators to debug if the paths remain correct in the EXE?
05-13-2025 08:15 AM
@ZYOng wrote:
Did you use probes or indicators to debug if the paths remain correct in the EXE?
Is there any reason why the paths would change in the executable, when the source code is working?
05-13-2025 09:18 AM
How have you defined the paths ?
05-13-2025 09:50 AM
I figured out the problem.
The main Python script was using os.getcwd() to get the current working directory, and then define the location of the SDK in relation to that.
The executable is not in the same folder directory as the SDK.
C:\Project\LabVIEW Source code
C:\Project\LabVIEW Source code\Python SDK\.py files
C:\Project\LabVIEW Source code\Main Python Script (this imports the SDK)
C:\Project\LabVIEW Executable
But even though the Python script hasn't changed location, the fact that it is being called by the LabVIEW executable in a different folder changes the Python script's current working directory. Which is weird.
So, I changed the path to the SDK to be an absolute path rather than using getcwd().