キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

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 件の賞賛
メッセージ1/9
7,672件の閲覧回数
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 件の賞賛
メッセージ2/9
7,668件の閲覧回数
Martin,
Thanks for the info.
I added the required *.lib files to my project and
that corrected the problem.

-Roger
0 件の賞賛
メッセージ3/9
7,641件の閲覧回数
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 件の賞賛
メッセージ4/9
7,636件の閲覧回数

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

すべてをダウンロード
0 件の賞賛
メッセージ5/9
5,220件の閲覧回数

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 件の賞賛
メッセージ6/9
3,796件の閲覧回数

hello 

 

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

0 件の賞賛
メッセージ7/9
3,230件の閲覧回数

Hi,

 

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

 

Best regards

0 件の賞賛
メッセージ8/9
3,227件の閲覧回数

Thanks for your answer !

best regards 

0 件の賞賛
メッセージ9/9
3,208件の閲覧回数