Geant4 Python Installation

While trying to install python modules, I come across this error while running cmake wondering if anyone has experienced the same issue

$ cmake /Users/Joe/Geant4/geant4.10.06.p02/environments/g4py

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


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:
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>)

Hi Benjamin,

Thanks for your prompt reply. I am working on cern lxplus and so pointing libraries from there.
I tried this command:

cmake -DCMAKE_INSTALL_PREFIX=/tmp/shilpi/geant4.10.06-install /tmp/shilpi/geant4.10.06.p02 -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_PYTHON=ON -DCMAKE_PREFIX_PATH=/cvmfs/

I get this warning:

– Found PythonInterp: /cvmfs/ (found suitable version “3.6.4”, minimum required is “3.0”)
– Found PythonLibs: /cvmfs/ (found version “3.6.8”)
CMake Warning at /cvmfs/ (message):
New Boost version may have incorrect or missing dependencies and imported
Call Stack (most recent call first):
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:

from GEANT4 import *

If I look inside /cvmfs/, I see this:

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.

Thanks a lot,

Seems that GEANT4 version 10.5 (to be precise: geant4.10.05.p01) works. Just listing down the steps in case it is useful for someone:

setenv PATH /cvmfs/$PATH
cmake -DCMAKE_INSTALL_PREFIX=/tmp/shilpi/geant4.10.05.p01-install /tmp/shilpi/geant4.10.05.p01 -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_OPENGL_X11=ON
make -j2
make install

cd /tmp/shilpi/geant4.10.05.p01/environments/g4py/
mkdir build
cd build
setenv GEANT4_INSTALL /tmp/shilpi/geant4.10.05.p01-install

To run:
setenv PYTHONPATH /tmp/shilpi/geant4.10.05.p01-install/lib64/:$PYTHONPATH

setenv PYTHONPATH /tmp/shilpi/geant4.10.05.p01-install/lib64/g4py/:$PYTHONPATH
setenv PYTHONPATH /tmp/shilpi/geant4.10.05.p01-install/lib64/Geant4/:$PYTHONPATH
setenv PYTHONPATH /tmp/shilpi/geant4.10.05.p01-install/lib64/tests/:$PYTHONPATH
setenv PYTHONPATH /tmp/shilpi/geant4.10.05.p01-install/lib64/examples/:$PYTHONPATH

Now any code can be run


I have another problem in running the test codes. I am using code inside: environments/g4py/tests/gtest01/
If I do:
python, I get this error:

Traceback (most recent call last):
File “”, line 103, in
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 in its lib directory so my guess its compiled with python2.7.

Do you know what could be causing this error?


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/

or by setting them up individually, e.g.

$ . /cvmfs/
$ . /cvmfs/
... 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.

I am getting an error while

>> import Geant4
** from G4interface import ***
Import error: cannot open shared file object: No such file or directory

this is in lib directory geant4-install folder, I have updated the
export GEANT4_INSTALL=/path

kindly Help