My project structure is as follows:
emb | CMakeLists.txt | main.c | python35.lib | stdlib.zip | _tkinter.pyd | +---include | | | | abstract.h | | accu.h | | asdl.h ... | | warnings.h | | weakrefobject.h | +---build | | emb.exe
stdlib.zip contains the DLLs, Libs , and site directories from the Python 3.5.2 installation, whose paths are added to sys.path
. I implicitly load python35.dll , referencing python35.lib , which contains stubs for all exported functions in the DLL. Here is the contents of CMakeLists.txt :
cmake_minimum_required(VERSION 3.6) project(embpython) set(SOURCE_FILES main.c) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) set(PYTHON_INCLUDE_DIR include) include_directories(${PYTHON_INCLUDE_DIR}) target_link_libraries( ${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/python35.lib ${CMAKE_CURRENT_LIST_DIR}/_tkinter.pyd)
And here is the contents of main.c :
#include <Python.h> int main(int argc, char** argv) { wchar_t* program_name; wchar_t* sys_path; char* path; program_name = Py_DecodeLocale(argv[0], NULL); if (program_name == NULL) { fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); exit(1); } Py_SetProgramName(program_name); path = "stdlib.zip;stdlib.zip/DLLs;stdlib.zip/Lib;" "stdlib.zip/site-packages"; sys_path = Py_DecodeLocale(path, NULL); Py_SetPath(sys_path); Py_Initialize(); PySys_SetArgv(argc, argv); PyRun_SimpleString("import tkinter\n"); Py_Finalize(); PyMem_RawFree(sys_path); PyMem_RawFree(program_name); return 0; }
Now here is the error I get:
Traceback (most recent call last): File "<string>", line 1, in <module> File " ... emb\stdlib.zip\Lib\tkinter\__init__.py", line 35, in <module> ImportError: DLL load failed: The specified module could not be found.
What am I doing wrong and how to fix it?
source share