ImportError: cannot import name 'gcd' from 'fractions'

GROMACS version:
GROMACS modification: Yes/No
Hello everyone, while doing protein ligand complex-ligand topology building step I am getting output stating that cannot import name 'gcd:. I am using python 3.10.6 with script cgenff_charmm2gmx_py3_nx2.py with networkx-2.3 and I am getting the below output:
/gromacs/test1$ python3 cgenff_charmm2gmx.py UNK unk_fix.mol2 unk.str charmm36-jul2021.ff
Traceback (most recent call last):
File “/mnt/c/users/admin/desktop/gromacs/test1/cgenff_charmm2gmx.py”, line 54, in
import networkx as nx
File “/home/shanu/.local/lib/python3.10/site-packages/networkx/init.py”, line 114, in
import networkx.generators
File “/home/shanu/.local/lib/python3.10/site-packages/networkx/generators/init.py”, line 14, in
from networkx.generators.intersection import *
File “/home/shanu/.local/lib/python3.10/site-packages/networkx/generators/intersection.py”, line 13, in
from networkx.algorithms import bipartite
File “/home/shanu/.local/lib/python3.10/site-packages/networkx/algorithms/init.py”, line 16, in
from networkx.algorithms.dag import *
File “/home/shanu/.local/lib/python3.10/site-packages/networkx/algorithms/dag.py”, line 23, in
from fractions import gcd
ImportError: cannot import name ‘gcd’ from ‘fractions’ (/usr/lib/python3.10/fractions.py)

Also, when I changed the networkx 2.5, I am getting below output:
/gromacs/test1$ python3 cgenff_charmm2gmx.py UNK unk_fix.mol2 unk.str charmm36-jul2021.ff
This script has been tested with NetworkX 2.3, and 2.4 is buggy.
Please install version 2.3 for best performance:
pip uninstall networkx
pip install networkx==2.3
NOTE 1: Code tested with Python 3.5.2 and 3.7.3. Your version: 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]

NOTE 2: Code tested with NetworkX 2.3. Your version: 2.5

NOTE 3: Please be sure to use the same version of CGenFF in your simulations that was used during parameter generation:
–Version of CGenFF detected in unk.str : 4.6
–Version of CGenFF detected in charmm36-jul2021.ff/forcefield.doc : 4.6

NOTE 4: To avoid duplicated parameters, do NOT select the ‘Include parameters that are already in CGenFF’ option when uploading a molecule into CGenFF.
Traceback (most recent call last):
File “/mnt/c/users/admin/desktop/gromacs/test1/cgenff_charmm2gmx.py”, line 1044, in
m.read_mol2_coor_only(mol2_name)
File “/mnt/c/users/admin/desktop/gromacs/test1/cgenff_charmm2gmx.py”, line 904, in read_mol2_coor_only
self.G.node[atomi][‘x’] = float(entry[2])
AttributeError: ‘Graph’ object has no attribute ‘node’. Did you mean: ‘_node’?

Please help me out with that.
Thank you

The script uses slightly older syntax, which needs to be updated. You can easily fix it with the advice here: python - Import Error: can't import name gcd from fractions - Stack Overflow

If you have further questions about this, please email me. This is not a GROMACS problem.

The “G.node” accessor was deprecated in 2.4
(https://networkx.org/documentation/stable/release/release_2.4.html#deprecations), you need to change line 904 in read_mol2_coor_only to “G.nodes”.

Kindly tell me how did you rectify this error as I’m facing the same problem as well.

Either use an older Python version (e.g. 3.7) or you will have to update the code. The syntax we use became deprecated some time ago and I haven’t had a chance to fix it and test but there are solutions posted online with a simple search.

Did you find any solution that works?

Is there a solution this issue? We are facing the same issue and not able to rectify. Any suggestion is highly appreciable.
Thanks in advance.

Did you try creating a virtual environment for python 3.7, then running gromacs commands from inside it? Stackoverflow got a thread discussing exactly this.