LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Runnning Python scripts from within LabWindows/CVI programs

I am trying to build the following code:

#include

int main(void)
{
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();

return 0;
}

I have set the include paths to the directory which contains the 'Python.h' include file.
I am getting the following link errors:

Undefined symbol '_Py_Initialize'
Undefined symbol '_Py_Finalize'
Undefined symbol '_PyRun_SimpleString'

All three function headers are contained in the include files referenced in 'Python.h.'

Why can't the linker find these functions?
0 Kudos
Message 1 of 9
(6,725 Views)
A header file alone will only tell the compiler what the function call looks like so it can compile your source code into an object file with an appropriate symbol table.

The linker needs to have a library or object file that contains the compiled code or dynamic link information for the functions in question. It then takes all of the object files and library files in the project and then reconciles the addresses of the functions in the symbol tables.

So you have to either come up with a.obj or a .lib file that contains the information the linker needs. The simplest way to use this file would be to add it to your project. If you are going to use it often, you can either put it in the CVI lib directory or tell CVI where the file exists in the library options.

Without such a file, the linker will simply complain that it can't find the symbols.
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 2 of 9
(6,721 Views)
Martin,
Thanks for the info.
I added the required *.lib files to my project and
that corrected the problem.

-Roger
0 Kudos
Message 3 of 9
(6,694 Views)
No problem, it's a common enough mistake and not necessarily obvious if you are not aware of how the compiler and linker "conspire" to put a program together.
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 4 of 9
(6,689 Views)

Hi there,

 

I'm faced with a similar problem. I want to implement python scripts in CVI 2017 and try to start a minimal project as 64bit application:

#include <utility.h>
#include "python.h"

int main (int argc, char *argv[])
{
	
  if (InitCVIRTE (0, argv, 0) == 0)
		return -1;	/* out of memory */

if(!Py_IsInitialized()) Py_Initialize(); Py_Finalize(); }

 At the Py_Initialize(); I get an unknown fault:

FATAL RUN-TIME ERROR: "minimal_test_main.c", line 12, col 5, thread id 7360: The program has caused a 'Unknown' fault at 0x00007FF91DBF36AE.

 

I'm using CVI 2017 on Windows 10 PRO

with

Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda custom (64-bit) on win32

 

In my project I have included

python37.lib from c:\ProgramData\Anaconda3\libs

 

using the modified pyconfig.h from Alex D found here and I add the 

define SIZEOF_WCHAR_T 2

to that file 

Also I try to create my own pyconfig based on the pyconfig from Alex and the original pyconfig that comes with Anaconda distribution. 

Another thing I tried is the use of python3.lib/dll instead of python37.lib/dll without luck.

 

Could someone help me to get python 3.7 runnning with CVI2017 64bit?

 

Best regards,

 

Thomas

Download All
0 Kudos
Message 5 of 9
(4,273 Views)

Hey , i have the same kind of question. I have a python code that contains functions that i want to use ib cvi. It ends in .py and i want to get access to those functions through the cvi. How can i do that?

 

ty

0 Kudos
Message 6 of 9
(2,849 Views)

hello 

 

Did you find the solution ? i have the same issue 😪

0 Kudos
Message 7 of 9
(2,283 Views)

Hi,

 

Unfortunately not. I started to migrate my CVI project completly to python .

 

Best regards

0 Kudos
Message 8 of 9
(2,280 Views)

Thanks for your answer !

best regards 

0 Kudos
Message 9 of 9
(2,261 Views)