OGRE_BUILD_COMPONENT_PYTHON

Problems building or running the engine, queries about how to use features etc.
Post Reply
geho2
Gnoblar
Posts: 3
Joined: Sat Sep 29, 2018 5:42 pm

OGRE_BUILD_COMPONENT_PYTHON

Post by geho2 »

Ogre Version: :1.11.2:
Operating System: :Windows 10:
Render System: :DirectX11:

Trying to compile Ogre.sln in Visual Studio 2017 with OGRE_BUILD_COMPONENT_PYTHON in Cmake but I get the following link error:

Code: Select all

1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyBool_Type referenced in function _wrap_OverlayElement_visitRenderables
Visual Studio comes with Python3 (\Shared\Python36_64). I suspect the error above could be because Ogre only supports Python2.x. Is that the case?
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by paroj »

no, it should work with both python2 and python3. I would guess libpython does not get linked in somehow. The Python Component was not tested much on Windows yet..
geho2
Gnoblar
Posts: 3
Joined: Sat Sep 29, 2018 5:42 pm

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by geho2 »

Below is a screenshot of the linker settings in VS 2017 using python37.lib. Below that the LNK2019 errors. If anyone has a suggestion for the linker settings to solve this, that would be much appreciated.

Image

Code: Select all

1>------ Build started: Project: _OgreOverlay, Configuration: Release x64 ------
2>------ Build started: Project: _OgreRTShader, Configuration: Release x64 ------
3>------ Build started: Project: _OgreBites, Configuration: Release x64 ------
4>------ Build started: Project: _Ogre, Configuration: Release x64 ------
2>   Creating library C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_OgreRTShader.lib and object C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_OgreRTShader.exp
1>   Creating library C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_OgreOverlay.lib and object C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_OgreOverlay.exp
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol _Py_NotImplementedStruct referenced in function SwigPyBuiltin__Ogre__Font_richcompare
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyBool_Type referenced in function _wrap_OverlayManager_createOverlayElementFromTemplate
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyFloat_Type referenced in function "int __cdecl SWIG_AsVal_float(struct _object *,float *)" (?SWIG_AsVal_float@@YAHPEAU_object@@PEAM@Z)
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_OverflowError referenced in function _wrap_OverlayManager_getScriptPatterns
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_RuntimeError referenced in function "void __cdecl SWIG_Python_AddErrorMsg(char const *)" (?SWIG_Python_AddErrorMsg@@YAXPEBD@Z)
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_NotImplementedError referenced in function _wrap_OverlayManager_createOverlayElementFromTemplate
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_TypeError referenced in function _wrap_OverlayManager_getOverlayElementFactoryMap
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyType_Type referenced in function PyInit__OgreOverlay
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol _PyWeakref_ProxyType referenced in function SWIG_Python_GetSwigThis
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol _PyWeakref_CallableProxyType referenced in function SWIG_Python_GetSwigThis
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_AttributeError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_IndexError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_MemoryError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_SyntaxError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_SystemError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_ValueError referenced in function _wrap_OverlayElement_setMaterial
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_ZeroDivisionError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
1>OgreOverlayPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_IOError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol _Py_NotImplementedStruct referenced in function SwigPyBuiltin__Ogre__RTShader__SGScriptTranslator_richcompare
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyBool_Type referenced in function _wrap_HardwareSkinning_setHardwareSkinningParam
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyFloat_Type referenced in function "int __cdecl SWIG_AsVal_float(struct _object *,float *)" (?SWIG_AsVal_float@@YAHPEAU_object@@PEAM@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_OverflowError referenced in function _wrap_ShaderGenerator_getShaderProfilesList
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_NotImplementedError referenced in function _wrap_ShaderGenerator_invalidateMaterialIlluminationPasses
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_TypeError referenced in function SwigPyObject_append
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyType_Type referenced in function PyInit__OgreRTShader
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol _PyWeakref_ProxyType referenced in function SWIG_Python_GetSwigThis
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol _PyWeakref_CallableProxyType referenced in function SWIG_Python_GetSwigThis
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_AttributeError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_IndexError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_MemoryError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_RuntimeError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_SyntaxError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_SystemError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_ValueError referenced in function _wrap___lshift__
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_ZeroDivisionError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
2>OgreRTShaderPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_IOError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
1>C:\Users\username\Documents\ogre-1.11.2\Builds\lib\Release\_OgreOverlay.pyd : fatal error LNK1120: 18 unresolved externals
1>Done building project "_OgreOverlay.vcxproj" -- FAILED.
2>C:\Users\username\Documents\ogre-1.11.2\Builds\lib\Release\_OgreRTShader.pyd : fatal error LNK1120: 18 unresolved externals
2>Done building project "_OgreRTShader.vcxproj" -- FAILED.
3>   Creating library C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_OgreBites.lib and object C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_OgreBites.exp
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol _Py_NotImplementedStruct referenced in function SwigPyBuiltin__OgreBites__Separator_richcompare
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyFloat_Type referenced in function "int __cdecl SWIG_AsVal_float(struct _object *,float *)" (?SWIG_AsVal_float@@YAHPEAU_object@@PEAM@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_OverflowError referenced in function "struct _object * __cdecl swig::from<class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > >(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const &)" (??$from@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@swig@@YAPEAU_object@@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_RuntimeError referenced in function "public: __cdecl Swig::DirectorMethodException::DirectorMethodException(char const *)" (??0DirectorMethodException@Swig@@QEAA@PEBD@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_NotImplementedError referenced in function _wrap_TrayManager_createParamsPanel
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_TypeError referenced in function _wrap_MouseMotionEvent_x_get
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyType_Type referenced in function PyInit__OgreBites
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyBool_Type referenced in function _wrap_SelectMenu_selectItem
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol _PyWeakref_ProxyType referenced in function SWIG_Python_GetSwigThis
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol _PyWeakref_CallableProxyType referenced in function SWIG_Python_GetSwigThis
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_AttributeError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_IndexError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_MemoryError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_SyntaxError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_SystemError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_ValueError referenced in function _wrap_TextBox__cursorPressed
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_ZeroDivisionError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
3>OgreBitesPYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_IOError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
3>C:\Users\username\Documents\ogre-1.11.2\Builds\lib\Release\_OgreBites.pyd : fatal error LNK1120: 18 unresolved externals
3>Done building project "_OgreBites.vcxproj" -- FAILED.
4>   Creating library C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_Ogre.lib and object C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_Ogre.exp
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol _Py_NotImplementedStruct referenced in function SwigPyBuiltin__Ogre__SceneManagerFactory_richcompare
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyFloat_Type referenced in function _wrap_Mesh_softwareVertexMorph
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyCFunction_Type referenced in function SWIG_Python_ConvertFunctionPtr
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PySlice_Type referenced in function _wrap_Techniques___delitem__
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_StopIteration referenced in function __catch$_wrap_SwigPyIterator___add__$3
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_OverflowError referenced in function _wrap_Pass_getTextureUnitStates
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_RuntimeError referenced in function _wrap_new_MaterialManager_Listener
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_NotImplementedError referenced in function _wrap_Skeleton__getAnimationImpl
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_TypeError referenced in function _wrap_IlluminationPassList_begin
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyType_Type referenced in function PyInit__Ogre
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyBool_Type referenced in function _wrap_Pass_setComputeProgram
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol _PyWeakref_ProxyType referenced in function SWIG_Python_GetSwigThis
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol _PyWeakref_CallableProxyType referenced in function SWIG_Python_GetSwigThis
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_AttributeError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_IndexError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_MemoryError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_SyntaxError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_SystemError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_ValueError referenced in function _wrap___ne__
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_ZeroDivisionError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
4>OgrePYTHON_wrap.obj : error LNK2019: unresolved external symbol PyExc_IOError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPEAU_object@@H@Z)
4>C:\Users\username\Documents\ogre-1.11.2\Builds\lib\Release\_Ogre.pyd : fatal error LNK1120: 21 unresolved externals
4>Done building project "_Ogre.vcxproj" -- FAILED.
5>------ Skipped Build: Project: PACKAGE, Configuration: Release x64 ------
5>Project not selected to build for this solution configuration 
6>------ Skipped Build: Project: INSTALL, Configuration: Release x64 ------
6>Project not selected to build for this solution configuration 
========== Build: 0 succeeded, 4 failed, 26 up-to-date, 2 skipped ==========
geho2
Gnoblar
Posts: 3
Joined: Sat Sep 29, 2018 5:42 pm

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by geho2 »

Below are all the linker options from: VS 2017 -> Linker -> Command Line.

Code: Select all

/OUT:"C:\Users\username\Documents\ogre-1.11.2\Builds\lib\Release\_Ogre.pyd" /MANIFEST /NXCOMPAT /PDB:"C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_Ogre.pdb" /DYNAMICBASE "..\..\lib\Release\OgreMain.lib" "C:\Users\username\AppData\Local\Programs\Python\Python37\libs\python37.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" /IMPLIB:"C:/Users/username/Documents/ogre-1.11.2/Builds/lib/Release/_Ogre.lib" /DLL /MACHINE:X64 /INCREMENTAL:NO /PGD:"C:\Users\username\Documents\ogre-1.11.2\Builds\lib\Release\_Ogre.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"_Ogre.dir\Release\_Ogre.pyd.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by paroj »

robertm
Gnoblar
Posts: 3
Joined: Sun Jan 06, 2019 3:46 am
x 1

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by robertm »

Here are my notes from my build process:

Python for Ogre3D on Windows


Ogre3D builds Python bindings with SWIG. SWIG isn't available on PyPi, but it is
available via `conda`, and `conda` can also install other dependencies such
as FreeType for us:

https://conda.io/miniconda.html

You will also need Microsoft Visual C++ 2018 (for Python 3.7, earlier versions
of Python require earlier versions of MSVC), and CMake (https://cmake.org/)
installed.

Once you have run the required installers, open an Anaconda command prompt
and create a new `conda` environment to host `ogre3d`:

Code: Select all

    conda create -n env_ogre python=3.7
    activate env_ogre
    conda install swig freetype freeimage
Optional: Ogre3D has hooks to convert NumPy arrays to C++ objects in Ogre3D, so
you will likely want it installed as well.

Code: Select all

    conda install numpy
Optional: If you want Qt5 bindings, recommend PySide2 installed via `pip`, as
it is the QtCorp officially supported wheel:

Code: Select all

    pip install pyside2
As the Python bindings have to be built against your particular Python
interpreter, the pre-built Ogre3D SDK does not include said Python bindings.
Some changes to the SWIG interface were recently made (2018-Dec-30) in
1.16.dev (9f92606) that require a recent clone:

Code: Select all

    git clone https://github.com/OGRECave/ogre.git
    cd ogre
Here we assume you already have all of the C++ dependencies installed. If not,
you will find out what is missing in `cmake`. Now we run `cmake-gui` from
the Ogre3D base directory to configure and generation our MSVC solution.

Code: Select all

    cmake-gui
Note: The default Ogre solution is win32. Presumably you will want to change
the project generator in `cmake-gui` to `Visual Studio 15 2018 Win64` to
target to 'x64' if you are working with a 64-bit Python interpreter. If you
want to support both memory address spaces you will need two separate Python
environments and most likely two separate Ogre build directories.

Optional: `conda` can be forced to make a 32-bit interpreter environment by setting

Code: Select all

    set CONDA_FORCE_32BIT=1
If you bother with both versions, I suggest making subdirectories `build32`
and `build64` as the binary build path. Hit the `Configure` button, select your
desired version of MSVC, and verify that the checkbox for
`OGRE_BUILD_COMPONENT_PYTHON` is checked.

IMPORTANT: at present (2018-Dec-30), you will also have to turn off
`OGRE_BUILD_COMPONENT_CSHARP` bindings in the configuration step, as they are
broken.

`Configure` again, then `Generate` and finally `Open Project` in MSVC2017.
Then you can build the entire solution, which takes about five minutes.

Co-locating the Components

From the base `ogre` directory, you will need to copy all files into some
shared folder. Following general Python package conventions, make a
directory `ogre3d` somewhere accessible and then a subdirectory `ogre3d`
which will hold the actual source files.

Copy into `ogre3d/ogre3d`:

- `.pyd` files are in `buildXX/lib/release`
- `.py` files are in `buildXX/Components/Python`
- `OgreNumpy.py` is in `Components/Python`
- All files from `buildXX/bin` should be co-located

Then in the `ogre3d/ogre3d` folder add an `__init__.py`:

Code: Select all

    from .__version__ import __version__

    # SWIG tries to import the .pyd files from the global namespace, e.g.
    #
    #   _Ogre = importlib.import_module('_Ogre')
    #
    # So path manipulation is the best work-around without changing how the 
    # upstream Ogre3D builds things.
    import os, sys, inspect
    current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    sys.path.insert(0, current_dir)

    from . import Ogre
    from . import OgreBites
    from . import OgreOverlay
    from . import OgreRTShader
    from . import OgreNumpy
and in the base `ogre3d` folder add a `setup.py`:

Code: Select all

    import setuptools
    import time, os.path as path, platform
    from setuptools import setup, find_packages, Extension
    import numpy as np
    import glob

    major_ver = 1
    minor_ver = 11
    nano_ver = 5
    branch = ''

    version = "%d.%d.%d%s" % (major_ver, minor_ver, nano_ver, branch)

    ##### Get info from associated text files #####
    # Write version.py
    with open( "ogre3d/__version__.py", 'w' ) as fh:
        fh.write( "__version__ = '" + version + "'\n" )

    # Get the long description from the README file
    try:
        with open(path.join('.', 'README.rst'), encoding='utf-8') as f:
            readmerst = f.read()
    except: # No long description
        readmerst = ""
        pass

    with open('requirements.txt') as f:
        requirements = f.read().splitlines()

    def setup_module():
        metadata = dict(
                        name = "ogre3d",
                        version = version,
                        description='Python Ogre3D',
                        long_description = readmerst,
                        author='Pavel Rojtberg',
                        author_email='',
                        url='',
                        license='MIT',
                        packages=find_packages(),
                        install_requires=requirements,
                        setup_requires=requirements,
                        entry_points={
                            # "gui_scripts" suppresses stdout, which we generally do not want
                            "console_scripts": [],
                            "gui_scripts": []
                            },
                        # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
                        extras_require={
                            },
                        ext_modules = [
                            ],
                        package_data={
                            '': ['*.pyd', '*.dll', '*.exe', '*.cfg', '*.dat'],
                            },
                        classifiers=[
                                # How mature is this project? Common values are
                                #   3 - Alpha
                                #   4 - Beta
                                #   5 - Production/Stable
                                'Development Status :: 5 - Production',
                        
                                # Pick your license as you wish (should match "license" above)
                                'License :: MIT',
                        
                                # Specify the Python versions you support here. In particular, ensure
                                # that you indicate whether you support Python 2, Python 3 or both.
                                'Programming Language :: Python :: 3',
                                'Programming Language :: Python :: 3.7',
                                
                                # OS
                                'Operating System :: Microsoft :: Windows',
                                'Operating System :: Microsoft :: Linux'
                            ],
                        keywords=[''],
                        #zip_safe=False, # DLLs cannot be zipped
        )

        setup(**metadata)


    if __name__ == '__main__':
        t0 = time.time()
        setup_module()
        t1 = time.time()
        print( "Completed: build/install time (s): %.3f" % (t1-t0) )
and `requirements.txt`:

Code: Select all

    # swig -- SWIG is actually only available via manual download or conda
    numpy
then you can install Ogre into any active Anaconda Python environment
(with the appropriate prereqs) as:

Code: Select all

    pip install .
or build wheels, etc. Note to use this Python package, import as:

Code: Select all

    from ogre3d import Ogre, OgreRTShader # etc.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by paroj »

wow.. all of the above is just a "make install" on linux.

A couple of notes:
1. there is Ogre.__version__
2. as of 1.11 there is no top-level "ogre3d" package, so you might want to drop it for cross-platform compatibility
3. for 1.12 I can introduce this if you can point me at some best practice guidelines. However I am currently leaning towards a "Ogre.Main", "Ogre.Overlay" scheme
4. there is no "README.rst" and the "README.md" probably requires some parsing
robertm
Gnoblar
Posts: 3
Joined: Sun Jan 06, 2019 3:46 am
x 1

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by robertm »

Yeah sorry, the `README.rst` is the text I posted.

What would be really nice for 1.12 or whenever would be to use Appveyor and Travis to build the Python module and then upload them to the PyPi repository. Then Ogre for Python could be installed via `pip install ogre3d`. Another option would be to try and make it available via `conda-forge`. I don't think the Python community is really up for complicated build processes, but there might be more Python people interested in Ogre if they could install it easily and reliably.

This name is taken:

https://pypi.org/project/OGRe/

This is available:

https://pypi.org/project/ogre3d/

The Python style guide PEP8 dictates that packages should be all lower case. PascalCase is normally reserved for class names, but in cases where you are wrapping C++ code often we see it anyway (e.g. Qt). Just something to keep in mind if you want to rename modules.

Anyway, if this is of interest I can turn on Appveyor and Travis for my fork, and look into adding Python to the continuous integration. Anaconda Python is available on both of those services. Then I would re-arrange the `Components/Python` directory to be a proper Python package, and then we can look at getting CMake to copy everything on build and finally run `python setup.py bdist_wheel` or `pip wheel .` and then upload it to BinTray.

This is an example of how wheel building is done for scientific packages:

https://github.com/MacPython/numexpr-wheels
niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 2

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by niubaty »

The Version of MSVC must be right if you are compiling the python component.
For example:

Code: Select all

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Your python version is 3.6 and the MSC v. == 1900 64 bit, so you have to choose the right version of MSVC

Code: Select all

MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
MSVC++ 15.0 _MSC_VER == 1910 (Visual Studio 2017)
MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
MSVC++ 9.0  _MSC_VER == 1500 (Visual Studio 2008)
You have to choose Visual Studio 2015 to compile the python componet and do not forget to choose the x64 in cmake
Otherwise, there will always be some link problems all the time.

I tried the Ogre v1.11.5 and compile successfully.

If your python version is 2.7, you may try Visual Studio 2008

Code: Select all

Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
There are some binding problems although...
I tried bites_sample.py ,but...

Code: Select all

F:\ogre0112\build36\sdk\bin>python bites_sample.py
Traceback (most recent call last):
  File "bites_sample.py", line 4, in <module>
    class SampleApp(Bites.ApplicationContext, Bites.InputListener):
AttributeError: module 'Ogre.Bites' has no attribute 'ApplicationContext'

Code: Select all

>>> from Ogre import Bites
>>> dir(Bites)
['AdvancedRenderControls', 'ApplicationContextBase', 'ApplicationContextBase_getDefaultMediaDir', 'BS_DOWN', 'BS_OVER', 'BS_UP', 'BUTTON_LEFT', 'BUTTON_MIDDLE', 'BUTTON_RIGHT', 'Button', 'CS_FREELOOK', 'CS_MANUAL', 'CS_ORBIT', 'CameraMan', 'CheckBox', 'DecorWidget', 'Event', 'FINGERDOWN', 'FINGERMOTION', 'FINGERUP', 'InputListener', 'KEYDOWN', 'KEYUP', 'KMOD_CTRL', 'KeyboardEvent', 'Keysym', 'Label', 'MOUSEBUTTONDOWN', 'MOUSEBUTTONUP', 'MOUSEMOTION', 'MOUSEWHEEL', 'MouseButtonEvent', 'MouseMotionEvent', 'MouseWheelEvent', 'NativeWindowPair', 'Ogre', 'ParamsPanel', 'ProgressBar', 'SDLK_DOWN', 'SDLK_ESCAPE', 'SDLK_F1', 'SDLK_F10', 'SDLK_F11', 'SDLK_F12', 'SDLK_F2', 'SDLK_F3', 'SDLK_F4', 'SDLK_F5', 'SDLK_F6', 'SDLK_F7', 'SDLK_F8', 'SDLK_F9', 'SDLK_KP_MINUS', 'SDLK_KP_PLUS', 'SDLK_LEFT', 'SDLK_LSHIFT', 'SDLK_PAGEDOWN', 'SDLK_PAGEUP', 'SDLK_RETURN', 'SDLK_RIGHT', 'SDLK_SPACE', 'SDLK_UP', 'SGTechniqueResolverListener', 'SWIG_PyInstanceMethod_New', 'SelectMenu', 'Separator', 'Slider', 'TL_BOTTOM', 'TL_BOTTOMLEFT', 'TL_BOTTOMRIGHT', 'TL_CENTER', 'TL_LEFT', 'TL_NONE', 'TL_RIGHT', 'TL_TOP', 'TL_TOPLEFT', 'TL_TOPRIGHT', 'TextBox', 'TouchFingerEvent', 'TrayListener', 'TrayManager', 'TrayManager_sceneToScreen', 'TrayManager_screenToScene', 'Widget', 'Widget_cursorOffset', 'Widget_fitCaptionToArea', 'Widget_getCaptionWidth', 'Widget_isCursorOver', 'Widget_nukeOverlayElement', '_Bites', '__builtin__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_newclass', '_object', '_swig_getattr', '_swig_property', '_swig_repr', '_swig_setattr', '_swig_setattr_nondynamic', 'disown_ApplicationContextBase', 'disown_InputListener', 'weakref', 'weakref_proxy']
Replace the ApplicationContext to ApplicationContextBase would make it work, but the app seems blocked and the camera can not be moved.
This should take some time to figure it out
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by paroj »

you probably compiled without SDL2 therefore ApplicationContext is missing. ApplicationContextBase lacks any input handling.

also take a look at:
https://github.com/OGRECave/ogre-meshvi ... /tag/19.01

for complete ogre python app on windows.
niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 2

Re: OGRE_BUILD_COMPONENT_PYTHON

Post by niubaty »

paroj wrote: Thu Jan 17, 2019 11:49 am you probably compiled without SDL2 therefore ApplicationContext is missing. ApplicationContextBase lacks any input handling.

also take a look at:
https://github.com/OGRECave/ogre-meshvi ... /tag/19.01

for complete ogre python app on windows.
Thank you @paroj
Post Reply