danomatika / swig-openframeworks

a SWIG interface for openFrameworks with included Makefile, submodule this in your language wrapper addons
Other
39 stars 11 forks source link

Add better explanation of how to use python bindings #26

Open george-gca opened 4 months ago

george-gca commented 4 months ago

Did everything needed for python binds, run this command and everything worked supposedly fine, no errors, just some warnings:

make desktop LANG=python MODULE_NAME=openframeworks ATTRIBUTES=true DEST_DIR=../src/binding

Full make log ``` ### Generating: openFrameworks desktop swig -c++ -python -O -small -modern -I../../../libs/openFrameworks -DMODULE_NAME=openframeworks -DOF_SWIG_ATTRIBUTES -o ../src/bindings/desktop/ofBindings.cpp openFrameworks.i Deprecated command line option: -modern. Ignored, this option is now always on. glm/vec2.i:19: Warning 362: operator= ignored glm/vec3.i:20: Warning 362: operator= ignored glm/vec4.i:23: Warning 362: operator= ignored glm/mat3.i:19: Warning 362: operator= ignored glm/mat4.i:20: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofFbo.h:51: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofFbo.h:53: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofTexture.h:438: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofTexture.h:439: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofImage.h:623: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofImage.h:626: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofImage.h:629: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofImage.h:632: Warning 362: operator= ignored ../../../libs/openFrameworks/3d/ofNode.h:22: Warning 362: operator= ignored ../../../libs/openFrameworks/3d/ofNode.h:23: Warning 362: operator= ignored ../../../libs/openFrameworks/3d/of3dPrimitives.h:19: Warning 362: operator= ignored ../../../libs/openFrameworks/math/ofMatrix4x4.h:382: Warning 362: operator= ignored ../../../libs/openFrameworks/math/ofQuaternion.h:163: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofShader.h:58: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofShader.h:60: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofVbo.h:26: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofVboMesh.h:11: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofPixels.h:228: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofPixels.h:229: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofPixels.h:232: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofPixels.h:471: Warning 383: operator++ ignored ../../../libs/openFrameworks/graphics/ofPixels.h:472: Warning 383: operator++ ignored ../../../libs/openFrameworks/graphics/ofPixels.h:500: Warning 383: operator++ ignored ../../../libs/openFrameworks/graphics/ofPixels.h:501: Warning 383: operator++ ignored ../../../libs/openFrameworks/graphics/ofPixels.h:502: Warning 384: operator-- ignored ../../../libs/openFrameworks/graphics/ofPixels.h:503: Warning 384: operator-- ignored ../../../libs/openFrameworks/graphics/ofPixels.h:509: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofPixels.h:510: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofPixels.h:545: Warning 383: operator++ ignored ../../../libs/openFrameworks/graphics/ofPixels.h:546: Warning 383: operator++ ignored ../../../libs/openFrameworks/graphics/ofPixels.h:547: Warning 384: operator-- ignored ../../../libs/openFrameworks/graphics/ofPixels.h:548: Warning 384: operator-- ignored ../../../libs/openFrameworks/graphics/ofPixels.h:615: Warning 383: operator++ ignored ../../../libs/openFrameworks/graphics/ofPixels.h:616: Warning 383: operator++ ignored ../../../libs/openFrameworks/graphics/ofTrueTypeFont.h:175: Warning 362: operator= ignored ../../../libs/openFrameworks/graphics/ofTrueTypeFont.h:178: Warning 362: operator= ignored ../../../libs/openFrameworks/types/ofColor.h:329: Warning 362: operator= ignored ../../../libs/openFrameworks/types/ofColor.h:335: Warning 362: operator= ignored ../../../libs/openFrameworks/types/ofRectangle.h:882: Warning 362: operator= ignored ../../../libs/openFrameworks/utils/ofXml.h:67: Warning 362: operator= ignored ../../../libs/openFrameworks/utils/ofXml.h:258: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofXml.h:268: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofXml.h:277: Warning 384: operator-- ignored ../../../libs/openFrameworks/utils/ofXml.h:287: Warning 384: operator-- ignored ../../../libs/openFrameworks/utils/ofXml.h:339: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofXml.h:345: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofXml.h:350: Warning 384: operator-- ignored ../../../libs/openFrameworks/utils/ofXml.h:356: Warning 384: operator-- ignored ../../../libs/openFrameworks/utils/ofXml.h:388: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofXml.h:389: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofXml.h:391: Warning 384: operator-- ignored ../../../libs/openFrameworks/utils/ofXml.h:392: Warning 384: operator-- ignored ../../../libs/openFrameworks/utils/ofFileUtils.h:122: Warning 362: operator= ignored ../../../libs/openFrameworks/utils/ofFileUtils.h:162: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofFileUtils.h:165: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofFileUtils.h:193: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofFileUtils.h:196: Warning 383: operator++ ignored ../../../libs/openFrameworks/utils/ofFileUtils.h:512: Warning 362: operator= ignored ../../../libs/openFrameworks/gl/ofFbo.h:16: Warning 503: Can't wrap 'operator |' unless renamed to a valid identifier. ../../../libs/openFrameworks/gl/ofFbo.h:20: Warning 503: Can't wrap 'operator &' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofMatrix4x4.h:1083: Warning 503: Can't wrap 'operator *' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofMatrix4x4.h:1087: Warning 503: Can't wrap 'operator *' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofQuaternion.h:71: Warning 509: Overloaded method ofQuaternion::operator [](int) const effectively ignored, ../../../libs/openFrameworks/math/ofQuaternion.h:70: Warning 509: as it is shadowed by ofQuaternion::operator [](int). ../../../libs/openFrameworks/math/ofVec2f.h:183: Warning 509: Overloaded method ofVec2f::operator [](int) const effectively ignored, ../../../libs/openFrameworks/math/ofVec2f.h:179: Warning 509: as it is shadowed by ofVec2f::operator [](int). ../../../libs/openFrameworks/math/ofVec2f.h:989: Warning 503: Can't wrap 'operator +' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec2f.h:990: Warning 503: Can't wrap 'operator -' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec2f.h:991: Warning 503: Can't wrap 'operator *' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec2f.h:992: Warning 503: Can't wrap 'operator /' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec3f.h:183: Warning 509: Overloaded method ofVec3f::operator [](int) const effectively ignored, ../../../libs/openFrameworks/math/ofVec3f.h:179: Warning 509: as it is shadowed by ofVec3f::operator [](int). ../../../libs/openFrameworks/math/ofVec3f.h:1061: Warning 503: Can't wrap 'operator +' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec3f.h:1062: Warning 503: Can't wrap 'operator -' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec3f.h:1063: Warning 503: Can't wrap 'operator *' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec3f.h:1064: Warning 503: Can't wrap 'operator /' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec4f.h:56: Warning 509: Overloaded method ofVec4f::operator [](int) const effectively ignored, ../../../libs/openFrameworks/math/ofVec4f.h:52: Warning 509: as it is shadowed by ofVec4f::operator [](int). ../../../libs/openFrameworks/math/ofVec4f.h:284: Warning 503: Can't wrap 'operator +' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec4f.h:285: Warning 503: Can't wrap 'operator -' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec4f.h:286: Warning 503: Can't wrap 'operator *' unless renamed to a valid identifier. ../../../libs/openFrameworks/math/ofVec4f.h:287: Warning 503: Can't wrap 'operator /' unless renamed to a valid identifier. ../../../libs/openFrameworks/graphics/ofGraphics.h:581: Warning 509: Overloaded method ofVertices(std::vector< glm::vec2,std::allocator< glm::vec2 > > const &) effectively ignored, ../../../libs/openFrameworks/graphics/ofGraphics.h:580: Warning 509: as it is shadowed by ofVertices(std::vector< glm::vec3,std::allocator< glm::vec3 > > const &). ../../../libs/openFrameworks/graphics/ofGraphics.h:580: Warning 509: Overloaded method ofVertices(std::vector< glm::vec3,std::allocator< glm::vec3 > > const &) effectively ignored, ../../../libs/openFrameworks/graphics/ofGraphics.h:581: Warning 509: as it is shadowed by ofVertices(std::vector< glm::vec2,std::allocator< glm::vec2 > > const &). ../../../libs/openFrameworks/graphics/ofGraphics.h:599: Warning 509: Overloaded method ofCurveVertices(std::vector< glm::vec2,std::allocator< glm::vec2 > > const &) effectively ignored, ../../../libs/openFrameworks/graphics/ofGraphics.h:598: Warning 509: as it is shadowed by ofCurveVertices(std::vector< glm::vec3,std::allocator< glm::vec3 > > const &). ../../../libs/openFrameworks/graphics/ofGraphics.h:598: Warning 509: Overloaded method ofCurveVertices(std::vector< glm::vec3,std::allocator< glm::vec3 > > const &) effectively ignored, ../../../libs/openFrameworks/graphics/ofGraphics.h:599: Warning 509: as it is shadowed by ofCurveVertices(std::vector< glm::vec2,std::allocator< glm::vec2 > > const &). ```

which generated 2 files:

Now, how exactly do I import it in python? I tried:

from openframeworks import *

and got:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gca/Software/of_v0.12.0_linux64gcc6_release/apps/pythonTest/src/bindings/desktop/openframeworks.py", line 12, in <module>
    import _openframeworks
ModuleNotFoundError: No module named '_openframeworks'

What am I missing?

danomatika commented 4 months ago

I assume you have to install it somewhere or at least add it to your search path. Also, I did not make the Python part of this and I have never built or tested it. It is likely out of date to some degree.

george-gca commented 4 months ago

I tried to point to it locally instead of using the system path. If you look closely to the error, it finds correctly the openframeworks.py file. The error is with an import inside that file.

danomatika commented 4 months ago

Dunno. Good luck. Ping @chaosct as he contributed the Python stuff.

george-gca commented 4 months ago

So, how does it work with lua? After I did the make part, how would I import and use it? Maybe I can make some parallel to it.

danomatika commented 4 months ago

Ah, I see the issue. This repo only hosts the SWIG interface. Running make generates the C++ bindings source files which you then build into your own app, with the scripting engine as well. The interface is not laid out to produce a dynamic library which you then load in Lua or Python, but to build into a openFrameworks app which can then run scripts in the embedded interpreter.

For Python, you are looking at https://github.com/chaosct/ofxPython which unfortunately does not seem to be maintained. I use Lua via https://github.com/danomatika/ofxLua which I do maintain.