Nipype - 'networkx' has no attribute 'to_scipy_sparse_matrix'

Summary of what happened:

Hi everyone, so I’m trying to run the workflow in the tutorial

It’s all good till I get to this line:
preproc.run(‘MultiProc’, plugin_args={‘n_procs’: 8})

Then, I get an error message about ‘networkx’ has no attribute ‘to_scipy_sparse_matrix’

Neither networkx or to_scipy_sparse_matrix appear in the code so I assume it’s an internal problem within Nipype? Does anyone know how to fix it?

I tried updating nipype and networkx but to no avail

Thanks in advance,
Shahar

Command used (and if a helper script was used, a link to the helper script or the command generated):

preproc.run(‘MultiProc’, plugin_args={‘n_procs’: 8})

Version:

nipype 1.8.6
networks 3.2.1

Relevant log outputs:

when I ran it through the cosnole I got:

Traceback (most recent call last):
File “…/shahar.bennoun/.conda/envs/abylab_fmri/lib/python3.11/site-packages/IPython/core/interactiveshell.py”, line 3526, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 1, in
preproc.run(‘MultiProc’)
File …/shahar.bennoun/.conda/envs/abylab_fmri/lib/python3.11/site-packages/nipype/pipeline/engine/workflows.py", line 638, in run
runner.run(execgraph, updatehash=updatehash, config=self.config)
File “…/shahar.bennoun/.conda/envs/abylab_fmri/lib/python3.11/site-packages/nipype/pipeline/plugins/base.py”, line 121, in run
self._generate_dependency_list(graph)
File “…/shahar.bennoun/.conda/envs/abylab_fmri/lib/python3.11/site-packages/nipype/pipeline/plugins/base.py”, line 437, in _generate_dependency_list
self.depidx = nx.to_scipy_sparse_matrix(
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘networkx’ has no attribute ‘to_scipy_sparse_matrix’

Weird enough, when I ran the code as whole I got a different message:

Traceback (most recent call last):
File “…/shahar.bennoun/PycharmProjects/Bunshin_jutsu/Nipype.py”, line 41, in
extract = Node(ExtractROI(t_min=4, t_size=-1, output_type=‘NIFTI’),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “…/shahar.bennoun/.conda/envs/bunshin/lib/python3.11/site-packages/nipype/interfaces/fsl/base.py”, line 171, in init
super(FSLCommand, self).init(**inputs)
File “…/shahar.bennoun/.conda/envs/bunshin/lib/python3.11/site-packages/nipype/interfaces/base/core.py”, line 629, in init
super(CommandLine, self).init(**inputs)
File “…/shahar.bennoun/.conda/envs/bunshin/lib/python3.11/site-packages/nipype/interfaces/base/core.py”, line 189, in init
BaseInterface._etelemetry_version_data = check_latest_version() or “n/a”
^^^^^^^^^^^^^^^^^^^^^^
File “…/shahar.bennoun/.conda/envs/bunshin/lib/python3.11/site-packages/nipype/init.py”, line 85, in check_latest_version
import etelemetry
File “…/shahar.bennoun/.conda/envs/bunshin/lib/python3.11/site-packages/etelemetry/init.py”, line 1, in
from .client import get_project, check_available_version
File “…/shahar.bennoun/.conda/envs/bunshin/lib/python3.11/site-packages/etelemetry/client.py”, line 4, in
import ci
ModuleNotFoundError: No module named ‘ci’

You are running nipype through multiple environments. The networkx issue was fixed in 1.8.6: https://github.com/nipy/nipype/pull/3538

It looks like the abylab_fmri environment just needs to update nipype.

For the bunshin environment, it looks like you somehow don’t have the whole dependency tree installed. I would probably delete this environments and start from scratch. Once you lose environment consistency, it’s generally not worth trying to fix.

1 Like

First of all thanks so much for the reply!

I did not notice I pasted the error messages from both condas.

When I ran the code in ‘bunshin’ console I got the exact same error message. That is probably because ‘bunshin’ is actually a clone of ‘abylab’ conda, with the only difference being nipype updated in ‘bunshin’…