Windows下QT中用C++调用Python之四 - 第三方扩展的使用

如需转载请标明出处: http://blog.csdn.net/itas109 

QQ技术交流群:129518033


Windows下QT中用C++调用Python之一 - 基础调用

Windows下QT中用C++调用Python之二 - 编译BUG处理

Windows下QT中用C++调用Python之三 - 基础参数的传入和传出


环境:
Python35: python-3.5.4   32位
QT: 5.6.2  32位

编译器:Visual Studio 2013

操作系统:windows 7 64Bit SP1

扩展:numpy‑1.13.3+mkl‑cp35‑cp35m‑win32.whl


在完成了基本的Python操作之后,我们需要引用第三方扩展进行更强大的处理。

这里我们以numpy为例做简单的说明

目标:引入numpy扩展,输出numpy的版本号


hello.py文件

# -*- coding: utf-8 -*-
import numpy as np

def hellonumpy():
	print("numpy version :",np.__version__)

def hello():
    print("hello python!")

def test_add(a, b):
	c = a + b
	print( a, "+", b," = ",c)
	return c

1.用Python安装numpy的whl


我们要使用numpy就需要先用pip命令对numpy进行安装。

安装过程这里就不说了。

如果不安装,C++调用Python会提示加载*.py失败,实际上语法有错误。


2.numpy的调用

    //获取hello模块中的hellonumpy函数
    PyObject* pFunhellonumpy= PyObject_GetAttrString(pModule,"hellonumpy");
    if(!pFunhellonumpy){
        infoData = "Get function pFunhellonumpy failed";
        qDebug()<< infoData;
    }

    //调用hellonumpy函数
    PyObject_CallFunction(pFunhellonumpy,NULL);

3.运行结果




觉得文章对你有帮助,可以用微信扫描二维码捐赠给博主,谢谢!


 如需转载请标明出处:http://blog.csdn.net/itas109 

QQ技术交流群:12951803


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

itas109

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值