question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'DiGraph' object has no attribute 'node'

See original GitHub issue

Describe the Bug

I’m getting an error when running one of the example scripts locally inside a virtualenv.

The script consists of the following snippet of code, which I have under a file named pid.py.

import dit
from dit.pid.helpers import compare_measures
from dit.pid.distributions import bivariates, trivariates
dit.ditParams['print.exact'] = dit.ditParams['repr.print'] = True
dit.ditParams['text.font'] = 'linechar'

for name, dist in bivariates.items():
    compare_measures(dist, name=name)

And the error appears to be with the networkx package.

Traceback (most recent call last):
  File ".../examples/pid.py", line 8, in <module>
    compare_measures(dist, name=name)
  File ".../venv/lib/python3.9/site-packages/dit/pid/helpers.py", line 51, in compare_measures
    vals = [pid.get_partial(node) for pid in pids]
  File ".../venv/lib/python3.9/site-packages/dit/pid/helpers.py", line 51, in <listcomp>
    vals = [pid.get_partial(node) for pid in pids]
  File ".../venv/lib/python3.9/site-packages/dit/pid/pid.py", line 247, in get_partial
    return self._lattice.node[node]['pi']
AttributeError: 'DiGraph' object has no attribute 'node'

Running Python v3.9.1 and here are the dependencies installed in the venv as shown in the pip freeze output.

boltons==20.2.1
contextlib2==0.6.0.post1
debtcollector==2.2.0
decorator==4.4.2
dit==1.2.3
networkx==2.5.1
numpy==1.20.2
pbr==5.5.1
prettytable==2.1.0
scipy==1.6.2
six==1.15.0
wcwidth==0.2.5
wrapt==1.12.1

To Reproduce

  • Create a virtualenv with Python 3
python3 -m venv venv
  • Activate the virtualenv
source ./venv/bin/activate
  • Install dit
pip install dit
  • Paste the code above into a file (e.g. pid.py).
  • Run pid.py
python pid.py

Expected Behavior

The example from the Jupyter notebook runs as expected.

Additional Context

I’ve seen that other repositories have run into similar problems (e.g. https://github.com/victorlei/smop/issues/165). However, if I try solutions such as pinning networkx==1.11, I run into other errors.

ImportError: cannot import name 'gcd' from 'fractions' (/usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/fractions.py)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Autoplecticcommented, Apr 20, 2021

please do!

1reaction
Autoplecticcommented, Apr 20, 2021

Hi @juancarlosfarah . I think all the networkx compatibility issues are fixed in master. Can you try installing the latest commit and see if that works for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

'DiGraph' object has no attribute 'node' #165 - victorlei/smop
Hi, I love the idea of this project, however, it does not work for me. See output below. Is there anything I can...
Read more >
AttributeError: 'DiGraph' object has no attribute '_node'
Now while running the code I am getting AttributeError: 'DiGraph' object has no attribute '_node' error. Following is the error message in ...
Read more >
DiGraph object has no attribute node解决方法 - CSDN博客
记录了使用smop将MATLAB代码转换成python代码时遇到问题'DiGraph' object has no attribute 'node'的2种解决方法.
Read more >
test suite failure: 'DiGraph' object has no attribute 'node' - GitLab
I see some 178 failed tests like the following when trying to run test suite of both Hyperkitty 1.2.2 and 1.3.0:
Read more >
Bug #1848499 “tests fail with networkx 2.4: “AttributeError: 'Di...”
tests fail with networkx 2.4: "AttributeError: 'DiGraph' object has no attribute 'node'". Bug #1848499 reported by Matt Riedemann on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found