Page 1 of 2

Pyhton module initializations

Posted: Tue May 15, 2012 1:09 pm
by cazfi
FreeOrion/AI/PythonAI.cpp: In constructor 'PythonAI::PythonAI()':
FreeOrion/AI/PythonAI.cpp:195:29: error: 'initfreeOrionLogger' was not declared in this scope
FreeOrion/AI/PythonAI.cpp:196:34: error: 'initfreeOrionAIInterface' was not declared in this scope

initXXX() are supposed to be provided by BOOST_PYTHON_MODULE(). I'm guessing here, but I think it has been changed to provide PyInit_XXX() instead in new versions (as I managed to get compiler errors from such a function after doing some modifications). Googling for examples also reveals that while everyone says that BOOST_PYTHON_MODULE() does define initXXX() those examples never explicitly call it. I cannot find definitive documentation, but it seems that initXXX() functions are just internal detail of handling these modules one is not supposed to call.

However, after I had just removed those lines compilation still failed due to another problem in same module, so I cannot say if their removal fixes or breaks things.

Re: Pyhton module initializations

Posted: Fri May 18, 2012 2:35 am
by Geoff the Medio
Use Boost 1.47 and things should work. Otherwise, you're on your own until FO updates the supported versions.

Re: Pyhton module initializations

Posted: Mon Jul 23, 2012 7:02 pm
by hasufell
I don't think that this is related to boost, it is rather related to the user having python-3 active, at least I can perfectly reproduce the error messages with this:

Code: Select all

make -f client/human/CMakeFiles/freeorion.dir/build.make client/human/CMakeFiles/freeorion.dir/depend
make[2]: Entering directory `/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build'
cd /var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890/FreeOrion /var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890/FreeOrion/client/human /var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build /var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build/client/human /var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build/client/human/CMakeFiles/freeorion.dir/DependInfo.cmake --color=
Dependee "/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build/client/human/CMakeFiles/freeorion.dir/DependInfo.cmake" is newer than depender "/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build/client/human/CMakeFiles/freeorion.dir/depend.internal".
Dependee "/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build/client/human/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build/client/human/CMakeFiles/freeorion.dir/depend.internal".
[35m[1mScanning dependencies of target freeorion
In file included from /usr/include/boost-1_48/boost/python/detail/wrap_python.hpp:50:0,
                 from /usr/include/boost-1_48/boost/python/detail/prefix.hpp:13,
                 from /usr/include/boost-1_48/boost/python/args.hpp:8,
                 from /usr/include/boost-1_48/boost/python.hpp:11,
                 from /var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890/FreeOrion/AI/PythonAI.h:3,
                 from /var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890/FreeOrion/AI/PythonAI.cpp:1:
/usr/include/python3.2/pyconfig.h:1182:0: warning: "_POSIX_C_SOURCE" redefined
/usr/include/features.h:164:0: note: this is the location of the previous definition
/usr/include/python3.2/pyconfig.h:1204:0: warning: "_XOPEN_SOURCE" redefined
/usr/include/features.h:166:0: note: this is the location of the previous definition
/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890/FreeOrion/AI/PythonAI.cpp: In constructor ‘PythonAI::PythonAI()’:
/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890/FreeOrion/AI/PythonAI.cpp:195:29: error: ‘initfreeOrionLogger’ was not declared in this scope
/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890/FreeOrion/AI/PythonAI.cpp:196:34: error: ‘initfreeOrionAIInterface’ was not declared in this scope
/usr/include/boost-1_48/boost/system/error_code.hpp: At global scope:
/usr/include/boost-1_48/boost/system/error_code.hpp:214:35: warning: ‘boost::system::posix_category’ defined but not used
/usr/include/boost-1_48/boost/system/error_code.hpp:215:35: warning: ‘boost::system::errno_ecat’ defined but not used
/usr/include/boost-1_48/boost/system/error_code.hpp:216:35: warning: ‘boost::system::native_ecat’ defined but not used
make[2]: *** [client/AI/CMakeFiles/freeorionca.dir/__/__/AI/PythonAI.cpp.o] Error 1
make[2]: Leaving directory `/var/tmp/portage/games-strategy/freeorion-0.3.17_p4890/work/freeorion-0.3.17_p4890_build'
make[1]: *** [client/AI/CMakeFiles/freeorionca.dir/all] Error 2
make sure you have python-2 active/installed/however you do that on your distro

This is a bug in the build system actually (which uses FindPythonLibs.cmake module). It should not allow the user to build with unsupported versions and give a meaningful error message.

Re: Pyhton module initializations

Posted: Mon Jul 23, 2012 7:31 pm
by Geoff the Medio
hasufell wrote:This is a bug in the build system actually (which uses FindPythonLibs.cmake module). It should not allow the user to build with unsupported versions and give a meaningful error message.
Can you suggest modifications to /client/AI/CMakeLists.txt that would restrict it to only accepting Python 2.x?

Code: Select all

find_package(PythonLibs)
if (PYTHONLIBS_FOUND)
    include_directories(${PYTHON_INCLUDE_PATH})
else ()
    message(FATAL_ERROR " library not found.")
endif ()

Re: Pyhton module initializations

Posted: Tue Jul 24, 2012 8:40 pm
by hasufell

Code: Select all

--- client/AI/CMakeLists.txt
+++ client/AI/CMakeLists.txt
@@ -33,6 +33,20 @@
 find_package(PythonLibs)
 if (PYTHONLIBS_FOUND)
     include_directories(${PYTHON_INCLUDE_PATH})
+    SET(_VERSION_REGEX
+      "^#define[ \t]+PY([A-Z_]*_VERSION)[ \t]+[\"]*([0-9A-Za-z\\.]+)[\"]*[ \t]*$")
+    FILE(STRINGS "${PYTHON_INCLUDE_DIR}/patchlevel.h" _VERSION_STRINGS
+       LIMIT_COUNT 10 REGEX ${_VERSION_REGEX})
+    FOREACH(_VERSION_STRING ${_VERSION_STRINGS})
+        STRING(REGEX REPLACE ${_VERSION_REGEX} "PYTHON\\1"
+           _VERSION_VARIABLE "${_VERSION_STRING}")
+        STRING(REGEX REPLACE ${_VERSION_REGEX} "\\2"
+           _VERSION_NUMBER "${_VERSION_STRING}")
+        SET(${_VERSION_VARIABLE} ${_VERSION_NUMBER})
+    ENDFOREACH(_VERSION_STRING ${_VERSION_STRINGS})
+    IF(PYTHON_MAJOR_VERSION EQUAL 3)
+        MESSAGE(FATAL_ERROR "Python 3 is not supported!")
+    ENDIF()
 else ()
     message(FATAL_ERROR " library not found.")
 endif ()
tested it and seems to work (on Linux). Code taken from http://www.cmake.org/pipermail/cmake/20 ... 45292.html

Re: Pyhton module initializations

Posted: Tue Jul 24, 2012 11:01 pm
by Geoff the Medio
What does it do, exactly? Find the python version for the specific python include directory, or of an include directory found on the system? That is, does specifying a particular location for python 2.7 make it work even if more than one version is installed?

Re: Pyhton module initializations

Posted: Wed Jul 25, 2012 1:10 pm
by hasufell
+# look in PYTHON_INCLUDE_DIR for patchlevel.h, which contains the
+# version number macros in all versions of python from 1.5 through
+# at least version 3.2, and set these vars: PYTHON_VERSION,
+# PYTHON_MAJOR_VERSION, PYTHON_MINOR_VERSION, PYTHON_MICRO_VERSION.
where PYTHON_INCLUDE_DIR is simply the one found by the cmake module "FindPythonLibs" which is already used in your code

Re: Pyhton module initializations

Posted: Wed Oct 03, 2012 2:34 am
by cazfi
The change made here just added more meaningful error message (that "python3 is not supported") but the error remains that when have several python versions installed, find_package() may find python3 and consequently leads to this error though python2 is available. It should be simply matter of specifying version 2 (and not default "any") for find_package(). I'm testing this.

Re: Pyhton module initializations

Posted: Wed Oct 03, 2012 3:06 am
by cazfi
With the attached patch I finally got compilation to pass on system with python3 as preferred python version (while still having python2 available)

Re: Pyhton module initializations

Posted: Wed Oct 03, 2012 3:53 am
by Geoff the Medio
Presumably the error message should say something about Python 2.x not being found, rather than just Python not found, since it will reject Python 3.x ?

And did you test that it actually builds and runs when configuring after that change when python 3 is present?

Re: Pyhton module initializations

Posted: Wed Oct 03, 2012 11:16 am
by hasufell
nice, I didn't even know the module takes a version argument

I will test it shortly too

Re: Pyhton module initializations

Posted: Wed Oct 03, 2012 8:49 pm
by cazfi
Geoff the Medio wrote:Presumably the error message should say something about Python 2.x not being found, rather than just Python not found, since it will reject Python 3.x ?
Yes, that occurred to me too, but only after I had already sent the patch.
Geoff the Medio wrote:And did you test that it actually builds and runs when configuring after that change when python 3 is present?
Yes. I have python2.6, python2.7, and python3.2 present in this system. Without the patch it aborts with "python3 not supported" message. With the patch it builds, and game launches.

Re: Pyhton module initializations

Posted: Wed Oct 03, 2012 8:51 pm
by Geoff the Medio
cazfi wrote:
Geoff the Medio wrote:Presumably the error message should say something about Python 2.x not being found, rather than just Python not found, since it will reject Python 3.x ?
Yes, that occurred to me too, but only after I had already sent the patch.
Could you update accordingly and re-attach?

Re: Pyhton module initializations

Posted: Wed Oct 03, 2012 9:12 pm
by cazfi
Geoff the Medio wrote:
cazfi wrote:
Geoff the Medio wrote:Presumably the error message should say something about Python 2.x not being found, rather than just Python not found, since it will reject Python 3.x ?
Yes, that occurred to me too, but only after I had already sent the patch.
Could you update accordingly and re-attach?
Here

Re: Pyhton module initializations

Posted: Wed Oct 03, 2012 9:17 pm
by Geoff the Medio
Thanks. I'll commit that later when I have a chance, unless someone else want to do so before I can.