LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Application (.exe) error with Python node, "ModuleNotFoundError"

Solved!
Go to solution

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'.

0 Kudos
Message 1 of 5
(208 Views)

Did you use probes or indicators to debug if the paths remain correct in the EXE?

-------------------------------------------------------
Applications Engineer | TME Systems
https://tmesystems.net/
0 Kudos
Message 2 of 5
(159 Views)

 


@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?

0 Kudos
Message 3 of 5
(146 Views)

How have you defined the paths ?

0 Kudos
Message 4 of 5
(136 Views)
Solution
Accepted by topic author abvenk

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().

0 Kudos
Message 5 of 5
(132 Views)