1.去主页下载源代码项目

2.编译下载下来的项目

3.新建项目填入下面代码

// pythonIncludeTest.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <Python.h> #pragma comment(lib, "python33.lib")
#pragma warning(disable:4996)
int _tmain(int argc, _TCHAR* argv[])
{ Py_SetProgramName(argv[]);
Py_SetPythonHome(L"G://SoftProject/cPython/pythonIncludeTest/Debug/");
Py_InitializeEx(); FILE * fp = NULL;
fp = fopen("G://SoftProject/cPython/pythonIncludeTest/Debug/main.py", "r"); if (fp == NULL)
{
return ;
}
PyRun_SimpleFile(fp, "main.py"); //PyRun_SimpleString("import sys\n"
// "print(sys.getfilesystemencoding())\n");
Py_Finalize();
scanf("exit");
return ;
}

4.添加包含目录和库目录(项目上右键,属性,配置属性,VC++目录)

包含目录指向源码的include目录,库目录指向PCbuild目录(要事先编译成功PCbuild目录就会有lib文件)

5.拷贝源码文件夹下的python33.dll(debug版是python33_d.dll)和Lib文件夹到当前目录,如果用到如ctypes等需要pyd的功能,还要编译该功能的对应项目,并拷贝相应的pyd文件到程序所在目录

python 会自动导入当先执行文件夹下的Lib文件夹下的文件,并且会根据模块如ctypes去当前文件夹找pyd文件如,ctypes_d.pyd

导入压缩版类库的代码版本:

// pythonIncludeTest.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <Python.h> #pragma comment(lib, "python33.lib")
#pragma warning(disable:4996)
int _tmain(int argc, _TCHAR* argv[])
{ Py_NoSiteFlag=;
Py_SetProgramName(argv[]);
Py_SetPythonHome(L"G://SoftProject/cPython/pythonIncludeTest/Debug/");
Py_InitializeEx(); char pycmd[]; // temporary buffer for forged Python script lines
snprintf(
pycmd,
sizeof(pycmd),
"import sys; sys.path = ['%s','%s/Lib']",
"G://SoftProject/cPython/pythonIncludeTest/Debug",
"G://SoftProject/cPython/pythonIncludeTest/Debug"
);
PyRun_SimpleString(pycmd); FILE * fp = NULL;
fp = fopen("G://SoftProject/cPython/pythonIncludeTest/Debug/main.py", "r"); if (fp == NULL)
{
return ;
}
PyRun_SimpleFile(fp, "main.py"); //PyRun_SimpleString("import sys\n"
// "print(sys.getfilesystemencoding())\n");
Py_Finalize();
scanf("exit");
return ;
}

怎么压缩所有源代码:http://docs.python.org/3.3/distutils/sourcedist.html

最新文章

  1. 【微信小程序开发•系列文章六】生命周期和路由
  2. [Machine-Learning] 熟悉 Matlab 中的 map
  3. ie浏览器的渲染原理
  4. c++ 中static关键字
  5. Hive通过查询语句向表中插入数据注意事项
  6. 解决java switch……case不能匹配字符串的问题
  7. Mysql的权限管理
  8. Farewell, 2015, welcome 2016
  9. 不想作死系列---virtualbox最小化安装centos6.5
  10. MySQL的数据备份以及pymysql的使用
  11. OpenCV 使用光流法检测物体运动
  12. Flask 框架介绍
  13. MySql 主从同步 (库名不同)
  14. 部署apache-tomcat环境
  15. BZOJ.3620.似乎在梦中见过的样子(KMP)
  16. PHP三种访问控制模式(public、protected、private)解析
  17. HDU 4325 Flowers(树状数组+离散化)
  18. Day36 数据库的操作
  19. C#简述(二)
  20. verilog语法实例学习(5)

热门文章

  1. 英语词根与单词的说文解字---词根示例1、第10页 st(at)
  2. 微信小程序------媒体组件(视频,音乐,图片)
  3. 19.并发容器之BlockingQueue
  4. socketserver源码简介
  5. Winform 导航菜单的方法
  6. Spring整合CXF发布及调用WebService
  7. 20165210 《网络对抗技术》week1 exp0 kali安装与配置
  8. Hibernate报错:Caused by: java.sql.SQLException: Field &#39;ID&#39; doesn&#39;t have a default value
  9. CRect类 的介绍
  10. mysql 数据传输报错 MySQL server has gone away With statement: