Python User? LabVIEW’s Got You Covered: Python Virtual Environments with LabVIEW
April 17, 2023
The Python programming language is quite popular these days and carries a vast ecosystem. It has a large community, and access to different sets of packages and libraries that are highly mature. That includes things like artificial intelligence (AI) and machine learning, and the different types of data analysis and processing elements that are required to handle these applications.
NI has added more Python functionality to LabVIEW 2023 with virtual environment support. As you learned in the previous blog, Drag and Drop Your Way Through Test and Measurement, LabVIEW is a graphical programming environment for applications that require test, measurement, and control. Hence, with the Python integration, your trusted test and measurement tool can be combined with cutting-edge Python, extending the functionality of LabVIEW. Note that this capability was initially added into LabVIEW back in 2018 and over time, the NI team has been increasing that functionality and making it more user-friendly.
To call Python in LabVIEW, users would use the Python Node. There are many situations in which someone might want to use Python: perhaps another team member or group, who is more familiar with Python, has developed a data analysis library or some other package. You can call that directly in LabVIEW and eliminate the need to go back and forth between tools. Furthermore, this does not require you to rewrite your Python code into LabVIEW code.
Use the Best Tool for the Job
This functionality was developed to help the user. If you’re familiar with Python or have team members who prefer Python, NI wants to make sure that you’re successful and can work together.
Don’t feel obligated to bring Python code into LabVIEW. It’s there if you need it, but not required as you may find that LabVIEW’s built-in features can handle your needs natively. It’s more about which tool is best suited to handle the job and what you’re comfortable with.
If you recall from the previous blog, LabVIEW is great at getting you from Step A to Step Z—connecting to hardware, acquiring and analyzing data, saving and sharing the data, and so on. That’s because there are pre-built functions for each of these steps. But if there’s a specific analysis that’s being built from scratch, users may prefer to go about it in Python—and that’s fine. There may also be some pre-existing code and/or algorithms written in Python that you want to re-use. This is an example of where you will want to import your Python code directly.
LabVIEW Is the Foundation
Use LabVIEW as the foundation of your test measurement code, for interfacing with instruments, pulling in data, and synchronizing everything. Then, use Python to take advantage of its vast feature set, including its libraries, and build that extra functionality on top of LabVIEW’s stable foundation, including high-precision measurements. The bottom line is the question of Python or LabVIEW needn’t be asked, because the answer is both.
According to Austin Stanton, a Solutions Marketer at NI, “In every update of LabVIEW since 2018, we've listened to the community, and improved our feature set to make it more LabVIEW/Python developer-friendly. The most recent release adds support for Python virtual environments, which is a best practice for anyone using Python.”
Note that by integrating Python functionality, NI is simply adding to the list of languages that it supports. That list already includes C/C++, .NET, and Mathwork’s MATLAB. Yes, MATLAB. LabVIEW has specific functions for calling these other languages, similarly to Python, which make this process straightforward. It's projects like this one that helped streamlined the Python integration, as NI used many of the lessons it learned by integrating MATLAB and other languages.
At the end of the day, the choice between Python and LabVIEW isn’t an "either or" proposition. The two languages can work in tandem to provide developers with a comprehensive solution for test, measurement, and control applications. As NI continues to listen to the needs of the community and improve the LabVIEW software, the possibilities for what developers can accomplish with this powerful toolset are endless.