Skip to content

Instantly share code, notes, and snippets.

@xkyii
Last active December 16, 2015 20:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xkyii/5496043 to your computer and use it in GitHub Desktop.
Python + C++相关
// get_pyfiles.cpp : 定义控制台应用程序的入口点。
//
#include <Python.h>
#include <Windows.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
// 得到当前可执行文件所在的目录
char szPath[MAX_PATH];
char szCmd[MAX_PATH];
::GetModuleFileNameA(NULL, szPath, sizeof(szPath));
char* p = strrchr(szPath, '\\');
if (p == NULL)
{
printf("Get module file name error!\n");
return -1;
}
*p = 0;
// 设定运行时的PATH
sprintf_s(szCmd, "PATH=%s\\dlls;%%PATH%%", szPath);
_putenv(szCmd);
printf(szCmd);
Py_NoSiteFlag = 1;
Py_Initialize();
PyRun_SimpleString("import main");
getchar();
return 0;
}
#-*- coding: utf-8 -*-
import sys
def main():
print(sys.path)
print('hello')
if __name__ == '__main__':
main()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment