Jump to content

Importing modules


Recommended Posts

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

Link to comment

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

Link to comment

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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.