lhe_parser.py as a library to import

Asked by Francesca Acanfora

Hi,
I'd like to have a parser to extract information from different kinds of event files. For now I focused on LHEF. I used madgraph/various/lhe_parser.py only as a file to run (in shell "python lhe_parser.py") containing the analysis in itself, as was in fact suggested by the 4 examples inside a main environment after all the classes and functions definitions. I want to use lhe_parser as a library to import in other .py files in which I eventually perform some analysis on the events. If I try and import the lhe_parser as a module in another .py I get errors like "no module named internal". These errors come from the import of "misc.py", "banner.py" and others. If I manually substitute the import of functions like "MadGraph5Error" or "InvalidCmd" I keep getting this kind of errors from other intertwined imports. I'd like to know wether there is an easy way to disentagle this threads.
I would add that the bottom lines of my profile file look like

export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/madgraph/various/
export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/madgraph/
export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/madgraph/iolibs
export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/models

Thanks a lot!
Francesca

Question information

Language:
English Edit question
Status:
Solved
For:
MadGraph5_aMC@NLO Edit question
Assignee:
No assignee Edit question
Solved by:
Olivier Mattelaer
Solved:
Last query:
Last reply:
Revision history for this message
Best Olivier Mattelaer (olivier-mattelaer) said :
#1

HI,

You should add the full MG5aMC directory in the path:
export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/

Note that this will likely not work anymore with python3.

Cheers,

Olivier

> On 15 Feb 2020, at 09:37, Francesca Acanfora <email address hidden> wrote:
>
> New question #688794 on MadGraph5_aMC@NLO:
> https://answers.launchpad.net/mg5amcnlo/+question/688794
>
> Hi,
> I'd like to have a parser to extract information from different kinds of event files. For now I focused on LHEF. I used madgraph/various/lhe_parser.py only as a file to run (in shell "python lhe_parser.py") containing the analysis in itself, as was in fact suggested by the 4 examples inside a main environment after all the classes and functions definitions. I want to use lhe_parser as a library to import in other .py files in which I eventually perform some analysis on the events. If I try and import the lhe_parser as a module in another .py I get errors like "no module named internal". These errors come from the import of "misc.py", "banner.py" and others. If I manually substitute the import of functions like "MadGraph5Error" or "InvalidCmd" I keep getting this kind of errors from other intertwined imports. I'd like to know wether there is an easy way to disentagle this threads.
> I would add that the bottom lines of my profile file look like
>
> export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/madgraph/various/
> export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/madgraph/
> export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/madgraph/iolibs
> export PYTHONPATH=$PYTHONPATH:/home/acanfora/MG5_aMC_v2.6.7/MG5_aMC_v2_6_7/models
>
> Thanks a lot!
> Francesca
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

Revision history for this message
Francesca Acanfora (facanfora) said :
#2

Thanks Olivier Mattelaer, that solved my question.