CMake Error at G4PythonHelpers.cmake:15 (file):
file RELATIVE_PATH must be passed a full path to the file:
Call Stack (most recent call first):
CMakeLists.txt:14 (include)
CMake Error at CMakeLists.txt:23 (geant4_add_feature):
Unknown CMake command “geant4_add_feature”.
As of 10.6.2, the Python binding can be done as part of the main Geant4 build. Apologies that this wasn’t updated in the docs. To enable it, build Geant4 as per the install guide, but add the option
-DGEANT4_USE_PYTHON=ON
This requires Python 3, plus Boost with Python3 support. If you want Geant4 built in Multithreaded mode with Python, this will also require the options:
Hi thank you very much! I’ve downloaded the python script in the lib directory but I can’t seem to execute it. Is there any way of running Geant4 in anaconda?
I have a question on the same. I installed it using commands:
cmake -DCMAKE_INSTALL_PREFIX=/tmp/shilpi/geant4.10.06-install /tmp/shilpi/geant4.10.06.p02 -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_PYTHON=ON
make -j2
make install
It got installed all fine.
But when I try this:
python
from Geant4 import *
It gave me this error: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
Could it be that the boost version is not compatible with the python version? For reference, I am using python version 3.6 and boost version 1.53.0
What would be the recommended version of boost? Also, how to specify with cmake?
Is that Boost version compiled for Python 3.6 (what OS/version is this on, and id the Boost install a system package or self installed)? That undefined symbol can be a symptom of using a Boost.Python that was compiled for Python 2.
Geant4’s Python interface has been built against Boost 1.70 successfully, and I’d guess that most recent versions should work fine. To point CMake to a specific Boost installed at, say /my/boost/install, add that path to CMAKE_PREFIX_PATH either in the environment, or as an argument to cmake (cmake -DCMAKE_PREFIX_PATH=/my/boost/install <otherargs>)
– Found PythonInterp: /cvmfs/cms.cern.ch/slc7_amd64_gcc820/cms/cmssw/CMSSW_10_6_1/external/slc7_amd64_gcc820/bin/python3 (found suitable version “3.6.4”, minimum required is “3.0”)
– Found PythonLibs: /cvmfs/cms.cern.ch/slc7_amd64_gcc820/cms/cmssw/CMSSW_10_6_1/external/slc7_amd64_gcc820/lib/libpython3.6m.so (found version “3.6.8”)
CMake Warning at /cvmfs/sft.cern.ch/lcg/contrib/CMake/3.14.2/Linux-x86_64/share/cmake-3.14/Modules/FindBoost.cmake:896 (message):
New Boost version may have incorrect or missing dependencies and imported
targets
Call Stack (most recent call first):
/cvmfs/sft.cern.ch/lcg/contrib/CMake/3.14.2/Linux-x86_64/share/cmake-3.14/Modules/FindBoost.cmake:1018 (_Boost_COMPONENT_DEPENDENCIES)
/cvmfs/sft.cern.ch/lcg/contrib/CMake/3.14.2/Linux-x86_64/share/cmake-3.14/Modules/FindBoost.cmake:1694 (_Boost_MISSING_DEPENDENCIES)
environments/g4py/CMakeLists.txt:11 (find_package)
– Boost version: 1.72.0
– Found the following Boost libraries:
– python
But everything compiled as usual. It still gave me the same error when I did:
python
from GEANT4 import *
If I look inside /cvmfs/cms.cern.ch/slc7_amd64_gcc820/external/boost/1.72.0-gchjei/lib/, I see this: libboost_python27.so
so probably its compiled with python2.7 - I am not sure…
So your suggestion would be install a boost version 1.7 using python3?
Also, may I ask which versions of GEANT4 can work with python2? I can try with that as well.
I have another problem in running the test codes. I am using code inside: environments/g4py/tests/gtest01/
If I do:
python test.py, I get this error:
Traceback (most recent call last):
File “test.py”, line 103, in
pg.SetParticleByName(“e-”)
Boost.Python.ArgumentError: Python argument types in
G4ParticleGun.SetParticleByName(G4ParticleGun, str)
did not match C++ signature:
SetParticleByName(G4ParticleGun*, std::__cxx11::basic_string<char, std::char_traits, std::allocator >)
which to me seems can arise if the compiled boost version is not compatible with the python version I am using. For reference, I am using python version 2.7.15+ and boost version 1.72.0 which seems to have libboost_python27.so in its lib directory so my guess its compiled with python2.7.
I’d recommend sticking with Geant4 10.6.2 as this has significant improvements to the build of the Python bindings. As you are running on lxplus, it would be easiest to use the LCG packages either via a view, e.g.
$ . /cvmfs/sft.cern.ch/lcg/releases/LCG_98python3/CMake/3.17.3/x86_64-centos7-gcc8-opt/CMake-env.sh
$ . /cvmfs/sft.cern.ch/lcg/releases/LCG_98python3/Boost/1.73.0/x86_64-centos7-gcc8-opt/Boost-env.sh
... other as needed ...
The views come with Geant4, but shouldn’t clash as long as when running you prepend the directories holding your Geant4 libraries and python modules to LD_LIBRARY_PATH and PYTHONPATH respectively.