取消
显示结果 
搜索替代 
您的意思是: 

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

已解决!
转到解答

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 项奖励
1 条消息(共 5 条)
1,203 次查看

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

-------------------------------------------------------
Applications Engineer | TME Systems
https://tmesystems.net/
-------------------------------------------------------
https://github.com/ZhiYang-Ong
0 项奖励
2 条消息(共 5 条)
1,154 次查看

 


@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 项奖励
3 条消息(共 5 条)
1,141 次查看

How have you defined the paths ?

4 条消息(共 5 条)
1,131 次查看
解答
已被主题作者 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 项奖励
5 条消息(共 5 条)
1,127 次查看