注意64位和32位的python版本,对应到VS的项目中,也应当使用x64或者x86*配套。 - **下载**python35的64位版本并安装。 - 配置python的环境变量:个人喜欢把默认添加的系统变量改为一个变量名%PY,地址一般是C:\Users\Administrator\AppData\Local\Programs\Python\Python35。
测试用,就用C++的win32控制台项目吧
代码示例是使用python创建一个文件并写入一个字符串,如下:
#include "stdafx.h" #include "python.h" int main() { Py_Initialize(); PyRun_SimpleString("import os"); PyRun_SimpleString("str = 'Hello World'"); PyRun_SimpleString("print(str)"); PyRun_SimpleString("fd = open('hellopy.txt', 'w')"); PyRun_SimpleString("fd.write('hello')"); PyRun_SimpleString("fd.close()"); Py_Finalize(); return 0; }