Coleman Posted July 1, 2010 Report Share Posted July 1, 2010 Hi, I have just started using LabView (8.2) and LabPython and I am having trouble importing modules. My code essentially looks like this: import socket class CLASS: def __init__(self,attribute): self.item = socket.socket() When running the code in LabView (filename Test2.vi), via New Session -> Set Script -> Compile -> Execute Script, I get the following error message: Error 1050 occurred at PYTHON Execute Script__ogtk.vi ->Test2.vi:<type 'exceptions.NameError'>, global name 'socket' is not defined The code works just fine outside of LabView. Is there some barrier I am unaware of, and is there a way to avoid/cirumvent it? Thanks! RColeman Quote Link to comment
rkanders Posted July 1, 2010 Report Share Posted July 1, 2010 Try re-installing your Python version. I had similar problem that went away after re-installing active state python. Hi, I have just started using LabView (8.2) and LabPython and I am having trouble importing modules. My code essentially looks like this: import socket class CLASS: def __init__(self,attribute): self.item = socket.socket() When running the code in LabView (filename Test2.vi), via New Session -> Set Script -> Compile -> Execute Script, I get the following error message: Error 1050 occurred at PYTHON Execute Script__ogtk.vi ->Test2.vi:<type 'exceptions.NameError'>, global name 'socket' is not defined The code works just fine outside of LabView. Is there some barrier I am unaware of, and is there a way to avoid/cirumvent it? Thanks! RColeman Quote Link to comment
Rolf Kalbermatter Posted July 1, 2010 Report Share Posted July 1, 2010 Try re-installing your Python version. I had similar problem that went away after re-installing active state python. Actually the issue here is most likely that sys.path is not initialized or at least doesn't contain the directory where your socket module is. LabPython does not do much of environment initialization when you create a session (and the Python script node is also simply creating a session implicitedly). So whatever the Python core doesn't find on its own you need to setup yourself. For the script node you would need to add the module directory path to sys.path and for a programmatic session you could execute a statement that sets sys.path accordingly before you execute a script that tries to import things. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.