python-embedding

Boost Python Embedding Error

走远了吗. 提交于 2019-12-11 09:44:55
问题 I've just built Boost Python on Windows 10 with an Anaconda version of Python 3.5 (64 bit). I used these instructions modified to my suit my installation and have successfully built the testCode.cpp using Visual Studio 2015: #include <boost/python.hpp> using namespace boost::python; int main() { try { Py_Initialize(); object main_module(( handle<>(borrowed(PyImport_AddModule("__main__"))))); object main_namespace = main_module.attr("__dict__"); handle<> ignored(( PyRun_String( "print (\"Hello

Embedding python: Version inconsistent with ProgramFullPath

十年热恋 提交于 2019-12-11 05:56:21
问题 I have anaconda Python first on my path, but a simple Python embedding example shows my Mac system python version instead, even though ProgramFullPath correctly points to anaconda python. Is there a way to correctly find / use anaconda python? Minimal example: #include <Python.h> #include <stdio.h> int main(void) { Py_Initialize(); printf("Python version:\n%s\n", Py_GetVersion()); printf("Python Program Full Path:\n%s\n", Py_GetProgramFullPath()); Py_Finalize(); return 0; } I compile with,

Embedding Python 3 - no builtins?

别来无恙 提交于 2019-12-11 05:54:13
问题 After much hair loss, I'm looking for help. I'm embedding Python 3.3 into a simple app. One unusual aspect is Python isn't on the path, but it all seems to load OK. But for some reason, nothing can be executed. Below is a small example program that shows the error: EDIT : I know the reference counting is horrible -- this is just a simple example. SetDllDirectory(L"D:\\dev\\python\\python33"); //so Python33.dll can be delay-loaded since not in the path Py_Initialize(); PyObject* pGlobals =

Is it possible to embed python without the standard library?

末鹿安然 提交于 2019-12-10 12:59:22
问题 Is it possible to embed python without the standard library? I'm working with a cmake build for python 2.7.6 and I've got a basic embedded script running, like so: #include <stdio.h> #include <Python.h> int main(int argc, char *argv[]) { /* Setup */ Py_SetProgramName(argv[0]); Py_Initialize(); /* Run the 'main' module */ int rtn = Py_Main(argc, _argv); Py_Finalize(); return rtn; } ..but when I run it, I get: ImportError: No module named site If I setup a correct $PYTHONHOME, it works fine;

Embedded Python does not work pointing to Python35.zip with NumPy - how to fix?

…衆ロ難τιáo~ 提交于 2019-12-10 11:41:31
问题 Okay here's the basic example from the Python website for a simple runpy.exe to run Python scripts below. It works fine using Visual Studio 2015 on x64 Windows after referencing the Python includes and linking to python35.lib for basic functions (the docs don't mention pyvenv.cfg must be in the EXE directory). However, calling a script that imports NumPy leads to this error ImportError: No module named 'numpy' Failed to load "eig" only when using embedded python35.zip , so how does one

Numpy import fails on multiarray extension library when called from embedded Python within a C++ application

≯℡__Kan透↙ 提交于 2019-12-08 23:12:48
问题 I'm running a C++ application which tries to run python using the https://docs.python.org/3.5/extending/embedding.html function calls. This is the error that the application error message pipes are giving me. class 'ImportError': Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). Otherwise reinstall numpy. Original error

Wrapping a Python function using NumPy arrays in C++

余生长醉 提交于 2019-12-08 05:44:02
问题 I have a bunch of functions written in python (for rapid prototyping). My main project is in C++ and I wanna call these functions from my C++ program. These functions use some specialized python modules like numpy, pyside etc. I tried using the "--embed" functionality of Cython to convert these functions to a C file and then compile that to an object file. Only problem is, Cython converts these functions into standalone programs, ie. makes a main() function in the .c files it creates. I don't

Embedding Python in Qt 5

与世无争的帅哥 提交于 2019-12-07 01:38:34
问题 I would like to embed Python interpreter in to a Qt 5 application. I have a working application in Qt 5 but when I put #include <Python.h> at the top (below Qt headers) the compilation breaks with ../sample/python3.3m/object.h:432:23: error: expected member name or ';' after declaration specifiers PyType_Slot *slots; /* terminated by slot==0. */ ~~~~~~~~~~~ ^ When I put Python header above the Qt headers it breaks with In file included from ../Qt5.0.1/5.0.1/clang_64/include/QtGui/QtGui:59: ..

“AttributeError: 'module' object has no attribute 'argv'” when using Python.h

拈花ヽ惹草 提交于 2019-12-06 19:16:41
问题 When messing around with Python.h I got this error: AttributeError: 'module' object has no attribute 'argv' C++ code: #include "stdafx.h" #include "C:/Python27/include/Python.h" #include <iostream> using namespace std; int main() { Py_Initialize(); PyRun_SimpleString("import sys\nprint sys.argv[0]"); } Which in Python is: import sys print sys.argv[0] What am I missing? 回答1: Conceptually, sys.argv should contain the arguments that Python was called with (and what it was called under). What

Embedding Python, works in main() but not in WinMain()

偶尔善良 提交于 2019-12-06 10:59:44
问题 I am embedding Python 3.4 into my application written in C++. When I enter the program with main() all works great, but when I use WinMain() it crashes. When Py_Initialize is called in main() everything works but in WinMain it fails. I am guessing it has something to do with the console not being there as WinMain() does not create a console. Thanks! 来源: https://stackoverflow.com/questions/22866596/embedding-python-works-in-main-but-not-in-winmain