LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a .py script inside a .VI, using anaconda's Libraries or specific python version (SystemExec.vi(?), MAC OSX)

Hi,

 

 

I'm new to both mac and LabView, so it may well be something obvious I'm missing.

 

I'm trying to use System Exec (http://zone.ni.com/reference/en-XX/help/371361L-01/glang/system_exec/ with LabVIEW 2014 on Mac OS X Mavericks) to call a python script to do some image processing after taking some data and saving images via LabView.

 

My problem is that I cannot figure out how to point it to the correct version/install of python to use, as it seems to use the pre-installed 2.7.5 apple version no matter whether that's set to be my default or not (and hence, it can't see my SciPy, PIL etc. packages that come with my Anaconda install).

It doesn't seem to matter whether I have certain packages installed for 2.7 accessable via the terminal, the LabView System Exec command line can't seem to find them either way and throws up an error if a script is called that imports them.

 

 

I've tried changing the working directory to the relevant anaconda/bin folder, I've also tried

cd /Applications/anaconda/bin; python <file.py> 

as the CL input to system exec, but it's not wanting to use anything other than the apple install. I've tried Anaconda installs with both python 2.7 and 3.4, so it doesn't seem to be down to the 3.* compatibility issues alone.

 

 

Printing the python version to a string indicator box in LV via python script gives the following:

 

2.7.5 (default, Mar 9 2014, 22:15:05)

[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]

 

Whereas via the terminal, the default version is the anaconda install I'd like to use, currently

 

Python 3.4.1 |Anaconda 2.1.0 (x86_64)| (default, Sep 10 2014, 17:24:09)

[GCC 4.2.1 (Apple Inc. build 5577)] on darwin

 

I can do which python3.4 on the sys exec CL input to get the correct /anaconda/bin location, but if I try  python3.4 <file.py>, I just get a Seg fault.

 

 

I've found examples for System Exec use and instructions for calling python scripts with specific versions, but neither works with Mac (frustratingly).

 

I've also tried editing the Path Environment Variable, and tried getting rid of the python 2.7 install entirely, but none of these work either (the latter just causing errors all over the shop).

 


 

 

 

 

So, in summary

I'd just like to know how to specify the python version LabView uses and to have use of the corresponding python libraries.

 

Either python version (2 or 3) will do, I'd just like to be able to use my libraries which came with Anaconda which I'll be writing my scripts with (which I installed as the correct packages are only compatible with a specific python version on Mac, which is not the specific version that Xcode was compatible with, argh).

 

All packages work normally when using the Anaconda version with the terminal or with Spyder.

 

Is there a function I can use other than System Exec? What am I missing?

 

Please help.

0 Kudos
Message 1 of 6
(5,461 Views)

Hi janedoe777,

 

I'm sorry to hear you're having trouble getting this VI to function properly. 

 

Can I just confirm that the script file you're trying to run using the System Exec.vi runs successfully with the correct version of Python if you execute it outside of LabVIEW? It can pick up all the correct Anaconda packages?

 

Whilst I'm waiting for your reply I'm going to do some research into this and see if anyone has had similar problems in the past. 

 

Thanks, 

Charlotte N.

 

0 Kudos
Message 2 of 6
(5,417 Views)

Hi,

 

Yes, it does.

 

The default python version (that the terminal uses) is Python 3.4 with all of the Scientific Python packages that come with Anaconda/Spyder.

 

 

Thanks

0 Kudos
Message 3 of 6
(5,367 Views)

Hi Janedoe777, 

 

I've carried out a bit more research into what you're seeing and SystemExec/LabVIEW do not have a version of Python (or other languages) that is a default. It just uses whatever default is set up on the computer your running. 

 

It seems like the default for your terminal is the Anaconda version so when you run your .py script it finds the correct version happily. But when you run it from outside of the terminal the default is still 2.7. All I can suggest is to make sure you set the correct version of python within the script your calling in the SystemExec file or change the default version for the actual .py file. I know in Windows you can specify the version of Python for a .py file, I'm unsure how you go about this in MacOS but it should be possible. As this appears to be a python configuration issue we recommend you get in touch with some of the python support groups on the internet.

 

I hope that what I have suggested leads you to the correct solution, 

 

Thanks, 

 

Charlotte N

0 Kudos
Message 4 of 6
(5,312 Views)

Im having the same problem now 

 

please can you tell me what the solution was ? (i'm using OS mac)

 

thanks

 

 

0 Kudos
Message 5 of 6
(4,345 Views)

Here is how I was finally able to call a python script from Mac OS using System.exec.vi when I want to use a specific version of Python other than the Mac OS default version 2.7.   The command line is this => ~/PycharmProjects/on_line_instruments/venv/bin/python SQLite_Main.py

The command line is a path to an instance of python installed in a virtual environment (aka venv) which, in my case is python 3.6, followed by a space followed by the name of the python script I am calling.  Notice I have no spaces (other than the space between 'python' and my script (SQLite_Main.py) and I have replaced all instances of the Mac OS file/folder delimiter (colon) with a forward slash.   It might work if the spaces are replaced with %20.  When I tried to use the full path it did not work.   It might be that the space between Macintosh and HD is what caused the problem.   When I use a relative path starting with the ~ (the user directory) it seems to work.

 

The working directory is a path to the folder containing the python script.   Hope this helps.

 

The standard input was left unwired.  

 

 

 

 

0 Kudos
Message 6 of 6
(4,017 Views)