From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
03-10-2011 10:00 AM
I have a piece of code, which runs in Python 2.5, but when called up from LabPython, fails with the following error:
Any ideas what may be causing this general type of error? I tried to include from wx import wx after the import statements, but this did not help either.
03-11-2011 10:57 AM
Hi Shultz,
Does this happen all the time or intermittently? Are you able to run other python scripts or do they all cause an error?
03-11-2011 11:05 AM - edited 03-11-2011 11:11 AM
I am able to run other python scripts through LabPython. I even wrote a simple GUI to test to compatability of wxPython, and it worked fine.This happens all the time with the script. The GUI does not even appear.
03-28-2011 08:53 AM
Shultz,
It sounds like you are able to call wxPython from LabPython, is this the case? When you created the simple test GUI did you use the "import wx" command?
03-28-2011 01:39 PM
@Biscotti wrote:
Shultz,
It sounds like you are able to call wxPython from LabPython, is this the case? When you created the simple test GUI did you use the "import wx" command?
Yes. I've used import wx and created a simple GUI using the wx commands.
03-28-2011 02:44 PM
If the code works when calling it in python and it does not work when using LabPython then there is likely a function in there that is not supported by LabPython. LabPython has not been updated since 2008 and is unfortunately not supported by National Instruments due to the third party and closed nature of its development.
I would suggest trying to call it as shown in Call Perl and Python Scripts from LabVIEW.
08-24-2011 04:17 AM
Passing here and saying hi. I have apparently a similar problem, though using other modules, and a solution to it. It seems that labpython has (at least on LV2010sp1/Python 2.7.1 on which I'm testing) an issue with visibility of names, such that names defined at the top level are not visible inside functions. My workaround was to declare them global. In particular I had a script starting with
import numpy
...
def myfunction(...):
# code using numpy functions
To have that work, I needed to declare global numpy after the import.
I think the problem has already been reported in the past (e.g. on OpenG forums, on lava.org forums) but I found nowhere such a simple solution...
I'm going to post about on labpython-users on sourceforge, maybe we could get some comment from Rolf.
Enrico
07-18-2012 10:23 AM
Did we ever find a fix for this problem? I'm running labpython and as soon as I try to get a variable from the global namespace using global, labpython forgets about it, MOST of the time. for instance:
myVar = [1,2,3,4,5] def foo(): global myVar return
labpython throws an error in the execute VI saying it can't find myVar. The funny thing is this only happens maybe 9/10 times, if I put the execute VI in a while loop with the error cluster status value wired to the continue condition, the script will eventually execute without error.
I read that Rolf doesn't have financial incentive to fix this problem. I would like this to be fixed very much. So much, that I'd be willing to work on it myself, or pay whoever may be concerned to resolve this.
07-18-2012 11:49 AM
IIRC, myVar would have to be declared global both in the function and in the caller; at least I do that and my stuff works.
I do have issues instead, if I rapid-fire the execute node too fast. Are you sure that the fact that you're eventually getting out of the loop does mean that the script executed correctly?
Enrico
07-19-2012 09:44 AM - edited 07-19-2012 09:44 AM
Here is an illustrative example of the problem I am having. The problem I showed earlier was when a script was importing a module that used global variables, which is similar, but different to this case.
Here are the contents of junk.py:
global myGlobalList #declared global in global namespace, not used in foo(), doesn't show up on variables list myGlobalList = [9,10,11] myNum = 5 #not declared global, shows up on variables list mylist = [1,2,3,4] #not declared global in the global namespace, but imported using global in foo() myOtherList = [5,6,7,8] #not delcared global, not used in foo(), shows up. def foo(): myNum = 9999 global mylist mylist.append(5) foo() mySum = 10 + myNum mylist[2] += 1 myOtherList[2] += 1
Here is the block diagram
here is the output:
From this, we can see that any thing preceeded by global, labpython forgets about. Now, before you go and tell me I shouldn't be using global variables in the first place, (and I tend to agree with you) the real problem is that I am importing other people's modules that use global variables, and it would be infeasible to re-write them.