Conda Geant4 Install

I have Anaconda with Python 3.7 and it’s up to date. I installed Geant4 as follows:
conda install -c conda-forge geant4

It worked as expected, but when I started writing a python program and wrote

from Geant4 import (all)

It returned with module Geant4 not found. I looked in anaconda file structure and found Geant4 10.6 directory with all the expected folders. In anaconda file structure under share directory I found a full set of shared libraries (.os) c files and data files. I found env variables pointing to the data files in the env. What I did not find was a Geant4 directory under python3.7/site-packages with .py files (Geant4.py) allowing Geant4 calls from python.

Has anyone encountered this problem when installing Geant4 via conda install on linux Ubuntu/Mint1.9 x64? How do you get the python site-package programs with a conda install?

Could you confirm the version of Geant4 that conda installed please (geant4-config --version should show this). IIRC, the python bindings in the conda package were only activated from version 10.7 onwards.

Thanks. geant4 version = 10.6.0

The interesting thing is that the conda geant4 install ( https://anaconda.org/conda-forge/geant4 ) claims to install version v10.7.2 with command ( conda install -c conda-forge geant4). Now it may be that the conda package manager checks the python version in Anaconda and installs the geant4 version it thinks is compatible. I have python 3.7, perhaps it’s looking for 3.8 or above. Can you advise the best course of action to install geant4 in the anaconda environment on x64 ubuntu/mint 19 linux?

I’m surprised it didn’t install the latest version - it’s a little while since I used conda, but could you try

$ conda install -c conda-forge geant4=10.7.2

or try installing it in a fresh environment:

$ conda create -c conda-forge -n geant4-test-env geant4=10.7.2

The available packages on conda-forge suggest that python3.7 versions are available.

Thanks for your help. I installed Anaconda-2021 based on python 3.8.11 and used your suggestion:

conda install -c conda-forge geant4=10.7.2

conda found a non-conflicting route and Geant4_10.7.2 installed cleanly. I checked the python bindings and they are there. I was able to run a test program. I hope this is helpful to someone else installing Geant4 in Anaconda.

I’ve written a small test program.

import sys
from Geant4 import *
#sys.exit()
import pyg4ometry
import demo_wp

------------------------------------------------------------------

#sys.exit()
def hini():
import g4py.MedicalBeam
import ROOT …

In the second line when I issue

from Geant4 import *

python restarts the kernel:

runfile(’/home/peter/Python_Work/Geant_demo1.py’, wdir=’/home/peter/Python_Work’)

Restarting kernel…

I know this because when I sys.exit right before the import this doesn’t happen

Any ideas?

All I can suggest here is to try the import of Geant4 alone without any of the other imports. The python bindings aren’t well tested in combination with ROOT/other packages so this may be revealing a bug.

Yes I tried that. I Also tried a small test program in spyder and jupyter notebook. Both crashed the kernel when I did: from Geant4 import *; or import Geant4; or any combination. I was able to: from Geant4 import * in the python command prompt on the terminal, that worked. However when I did anything else import ROOT; or import pyg4.Qmaterials or anything else it said “module not found.” So clearly it’s installed but parts are missing or the environment is incomplete. If you have any suggestions as to how to fix the environment I’d like to hear them. Also, has anyone you know made this work in jupyter notebooks cause something there crashes the kernel that doesn’t crash it in the command prompt.

At the command prompt it gives:


Geant4 version Name: geant4-10-07-patch-02 [MT] (11-June-2021)
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/


Visualization Manager instantiating with verbosity “warnings (3)”…

However when I do anything else, i.e. import g4py.MedicalBeam or import ROOT it can’t find the module. My Geant4 installation is under ./anaconda3, when I look for the g4py directory (find ./ -name g4py) it’s not there. I can’t find it anywhere on my system. Do you know anyone who has successfully run Geant4 under Anaconda?

Finally I want to point out that the basic problem at this point is that “Import Geantt4” crashes the kernel in jupyter and spyder. At the command prompt I get the following:

import Geant4


Geant4 version Name: geant4-10-07-patch-02 [MT] (11-June-2021)
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/


Visualization Manager instantiating with verbosity “warnings (3)”…

dir(Geant4)
[‘ApplyUICommand’, ‘Avogadro’, ‘Bohr_radius’, ‘CreateBox’, ‘CreateCons’, ‘CreateEllipsoid’, ‘CreateEllipticalCone’, ‘CreateEllipticalTube’, ‘CreateHype’, ‘CreateOrb’, ‘CreatePara’, ‘CreatePolycone’, ‘CreatePolyhedra’, ‘CreateSphere’, ‘CreateTet’, ‘CreateTorus’, ‘CreateTrap’, ‘CreateTrd’, ‘CreateTubs’, ‘CreateTwistedBox’, ‘CreateTwistedTap’, ‘CreateTwistedTrd’, ‘CreateTwistedTubs’, ‘EAxis’, ‘EInside’, ‘EVolume’, ‘FTFP_BERT’, ‘FTFP_BERT_ATL’, ‘FTFP_BERT_HP’, ‘FTFP_BERT_TRV’, ‘FTFP_INCLXX’, ‘FTFP_INCLXX_HP’, ‘FTF_BIC’, ‘G4ASCIITree’, ‘G4ApplicationState’, ‘G4AtomicShells’, ‘G4BestUnit’, ‘G4BooleanSolid’, ‘G4Box’, ‘G4ChordFinder’, ‘G4ClassificationOfNewTrack’, ‘G4Color’, ‘G4Cons’, ‘G4CrossSectionHandler’, ‘G4DAWNFILE’, ‘G4Date’, ‘G4DecayTable’, ‘G4DynamicParticle’, ‘G4Element’, ‘G4ElementTable’, ‘G4Ellipsoid’, ‘G4EllipticalCone’, ‘G4EllipticalTube’, ‘G4EmCalculator’, ‘G4Event’, ‘G4EventManager’, ‘G4Exception’, ‘G4ExceptionHandler’, ‘G4ExceptionSeverity’, ‘G4Field’, ‘G4FieldManager’, ‘G4GeometryManager’, ‘G4HepRep’, ‘G4HepRepFile’, ‘G4Hype’, ‘G4IntersectionSolid’, ‘G4Isotope’, ‘G4IsotopeTable’, ‘G4LogicalVolume’, ‘G4MagneticField’, ‘G4Material’, ‘G4MaterialTable’, ‘G4Navigator’, ‘G4NistManager’, ‘G4OpenGLImmediateX’, ‘G4OpenGLStoredX’, ‘G4Orb’, ‘G4PVPlacement’, ‘G4PVReplica’, ‘G4Para’, ‘G4ParticleDefinition’, ‘G4ParticleGun’, ‘G4ParticleTable’, ‘G4PhysListFactory’, ‘G4Polycone’, ‘G4Polyhedra’, ‘G4PrimaryParticle’, ‘G4PrimaryVertex’, ‘G4ProcVector’, ‘G4ProcessManager’, ‘G4ProcessTable’, ‘G4ProcessType’, ‘G4ProcessVectorDoItIndex’, ‘G4ProcessVectorOrdering’, ‘G4ProcessVectorTypeIndex’, ‘G4ProductionCutsTable’, ‘G4RandGauss’, ‘G4RandomDirection’, ‘G4RayTracer’, ‘G4RayTracerX’, ‘G4Region’, ‘G4RotationMatrix’, ‘G4Run’, ‘G4RunManager’, ‘G4RunManagerKernel’, ‘G4Sphere’, ‘G4StackManager’, ‘G4State’, ‘G4StateManager’, ‘G4Step’, ‘G4StepPoint’, ‘G4StepStatus’, ‘G4String’, ‘G4StringVector’, ‘G4SubtractionSolid’, ‘G4Tet’, ‘G4ThreeVector’, ‘G4ThreeVectorVector’, ‘G4Timer’, ‘G4Torus’, ‘G4TouchableHistory’, ‘G4Track’, ‘G4TrackStatus’, ‘G4TrackingManager’, ‘G4Transform3D’, ‘G4TransportationManager’, ‘G4Trap’, ‘G4Trd’, ‘G4Tubs’, ‘G4TwistedBox’, ‘G4TwistedTrap’, ‘G4TwistedTrd’, ‘G4TwistedTubs’, ‘G4TwoVector’, ‘G4UIcommand’, ‘G4UIcommandTree’, ‘G4UImanager’, ‘G4UIparameter’, ‘G4UniformMagField’, ‘G4UniformRand’, ‘G4UnionSolid’, ‘G4UnitDefinition’, ‘G4UnitsCategory’, ‘G4UnitsContainer’, ‘G4UnitsTable’, ‘G4UserEventAction’, ‘G4UserLimits’, ‘G4UserRunAction’, ‘G4UserStackingAction’, ‘G4UserSteppingAction’, ‘G4UserTrackingAction’, ‘G4VCrossSectionHandler’, ‘G4VERSION_NUMBER’, ‘G4VGraphicsSystem’, ‘G4VModularPhysicsList’, ‘G4VPhysicalVolume’, ‘G4VPhysicsConstructor’, ‘G4VProcess’, ‘G4VRML1File’, ‘G4VRML2File’, ‘G4VSensitiveDetector’, ‘G4VSolid’, ‘G4VTouchable’, ‘G4VUserDetectorConstruction’, ‘G4VUserPhysicsList’, ‘G4VUserPrimaryGeneratorAction’, ‘G4Version’, ‘G4VisAttributes’, ‘G4VisManager’, ‘G4digits_hits’, ‘G4doubleVector’, ‘G4event’, ‘G4geometry’, ‘G4global’, ‘G4graphics_reps’, ‘G4intVector’, ‘G4intercoms’, ‘G4interfaces’, ‘G4materials’, ‘G4particles’, ‘G4physicslists’, ‘G4processes’, ‘G4run’, ‘G4track’, ‘G4tracking’, ‘G4visualization’, ‘GeV’, ‘HepJamesRandom’, ‘HepRandom’, ‘HepRandomEngine’, ‘LBE’, ‘ListPhysicsList’, ‘MeV’, ‘NuBeam’, ‘PeV’, ‘PyG4ParticleList’, ‘QBBC’, ‘QGSP_BERT’, ‘QGSP_BERT_HP’, ‘QGSP_BIC’, ‘QGSP_BIC_AllHP’, ‘QGSP_BIC_HP’, ‘QGSP_FTFP_BERT’, ‘QGSP_INCLXX’, ‘QGSP_INCLXX_HP’, ‘QGS_BIC’, ‘RandBit’, ‘RanecuEngine’, ‘Ranlux64Engine’, ‘RanluxEngine’, ‘ResetG4PyCoutDestination’, ‘STP_Pressure’, ‘STP_Temperature’, ‘SetG4PyCoutDestination’, ‘Shielding’, ‘StartUISession’, ‘TeV’, ‘author’, ‘builtins’, ‘cached’, ‘date’, ‘doc’, ‘file’, ‘loader’, ‘name’, ‘package’, ‘path’, ‘spec’, ‘version’, ‘_atree’, ‘_dawn’, ‘_heprep_file’, ‘_heprep_xml’, ‘_list_material’, ‘_material_class_list’, ‘_one_event’, ‘_opengl_ix’, ‘_opengl_sx’, ‘_q_opengl_ix’, ‘_q_opengl_ixm’, ‘_q_opengl_sx’, ‘_q_opengl_sxm’, ‘_q_raytracer_x’, ‘_qfind’, ‘_raytracer’, ‘_raytracer_x’, ‘_run_abort’, ‘_visdriver_list’, ‘_vrml1’, ‘_vrml2’, ‘alpha_rcl2’, ‘ampere’, ‘amu’, ‘amu_c2’, ‘angstrom’, ‘atmosphere’, ‘bar’, ‘barn’, ‘becquerel’, ‘c_light’, ‘c_squared’, ‘candela’, ‘centimeter’, ‘centimeter2’, ‘centimeter3’, ‘classic_electr_radius’, ‘cm’, ‘cm2’, ‘cm3’, ‘colortable’, ‘coulomb’, ‘curie’, ‘deg’, ‘degree’, ‘eV’, ‘e_SI’, ‘e_squared’, ‘electron_Compton_length’, ‘electron_charge’, ‘electron_mass_c2’, ‘electronvolt’, ‘elm_coupling’, ‘eplus’, ‘epsilon0’, ‘farad’, ‘fermi’, ‘fine_structure_const’, ‘float_rgb’, ‘g’, ‘gApplyUICommand’, ‘gControlExecute’, ‘gElementTable’, ‘gEmCalculator’, ‘gEventManager’, ‘gExceptionHandler’, ‘gG4Date’, ‘gG4VERSION_NUMBER’, ‘gG4Version’, ‘gGeometryManager’, ‘gGetCurrentValues’, ‘gMaterialTable’, ‘gNistManager’, ‘gParticleIterator’, ‘gParticleTable’, ‘gProcessTable’, ‘gProductionCutsTable’, ‘gRunManager’, ‘gRunManagerKernel’, ‘gStackManager’, ‘gStartUISession’, ‘gStateManager’, ‘gTerminate’, ‘gTrackingManager’, ‘gTransportationManager’, ‘gUImanager’, ‘gVisManager’, ‘gauss’, ‘gigaelectronvolt’, ‘gram’, ‘gray’, ‘h_Planck’, ‘halfpi’, ‘hbar_Planck’, ‘hbarc’, ‘hbarc_squared’, ‘henry’, ‘hepunit’, ‘hertz’, ‘int_rgb’, ‘joule’, ‘kGasThreshold’, ‘k_Boltzmann’, ‘keV’, ‘kelvin’, ‘kg’, ‘kiloelectronvolt’, ‘kilogauss’, ‘kilogram’, ‘kilohertz’, ‘kilometer’, ‘kilometer2’, ‘kilometer3’, ‘kilovolt’, ‘km’, ‘km2’, ‘km3’, ‘lumen’, ‘lux’, ‘m’, ‘m2’, ‘m3’, ‘megaelectronvolt’, ‘megahertz’, ‘megavolt’, ‘meter’, ‘meter2’, ‘meter3’, ‘mg’, ‘microampere’, ‘microbarn’, ‘microfarad’, ‘micrometer’, ‘microsecond’, ‘milliampere’, ‘millibarn’, ‘millifarad’, ‘milligram’, ‘millimeter’, ‘millimeter2’, ‘millimeter3’, ‘milliradian’, ‘millisecond’, ‘mm’, ‘mm2’, ‘mm3’, ‘mole’, ‘mrad’, ‘ms’, ‘mu0’, ‘nanoampere’, ‘nanobarn’, ‘nanofarad’, ‘nanometer’, ‘nanosecond’, ‘neutron_mass_c2’, ‘newton’, ‘ns’, ‘ohm’, ‘parsec’, ‘pascal’, ‘pc’, ‘perCent’, ‘perMillion’, ‘perThousand’, ‘petaelectronvolt’, ‘pi’, ‘pi2’, ‘picobarn’, ‘picofarad’, ‘picosecond’, ‘print_version’, ‘proton_mass_c2’, ‘rad’, ‘radian’, ‘s’, ‘second’, ‘signal’, ‘sr’, ‘steradian’, ‘teraelectronvolt’, ‘tesla’, ‘threading’, ‘twopi’, ‘twopi_mc2_rcl2’, ‘universe_mean_density’, ‘volt’, ‘watt’, ‘weber’]

And so I have what I need to run Geant4, i.e.

Geant4.G4geometry
<module ‘Geant4.G4geometry’ from ‘/home/peter/anaconda3/lib/python3.8/site-packages/Geant4/G4geometry.so’>

The immediate problem is that in the IDE it crashes the python kernel. Any ideas?