PyCG icon indicating copy to clipboard operation
PyCG copied to clipboard

Can't add edge to a non existing node

Open JaewonHur opened this issue 2 years ago • 1 comments

When I try to run a simple example on PyCG, it always raises exception pycg.machinery.imports.ImportManagerError.

My setting is as follow: python version: 3.6.9 pycg commit: 99c991

I setup test directory like

mypkg/
  __init__.py
  main.py

and main.py contains

def foo():
    bar()
def bar():
    print('bar')

Running pycg --package mypkg mypkg/main.py -o cg.json raises an exception as follow:

Traceback (most recent call last):
  File "/home/jwhur/.pyenv/versions/3.6.9/bin/pycg", line 11, in <module>
    sys.exit(main())
  File "/home/jwhur/.pyenv/versions/3.6.9/lib/python3.6/site-packages/pycg/__main__.py", line 79, in main
    cg.analyze()
  File "/home/jwhur/.pyenv/versions/3.6.9/lib/python3.6/site-packages/pycg/pycg.py", line 157, in analyze
    self.class_manager, self.module_manager)
  File "/home/jwhur/.pyenv/versions/3.6.9/lib/python3.6/site-packages/pycg/pycg.py", line 147, in do_pass
    modules_analyzed=modules_analyzed, *args, **kwargs)
  File "/home/jwhur/.pyenv/versions/3.6.9/lib/python3.6/site-packages/pycg/processing/preprocessor.py", line 33, in __init__
    super().__init__(filename, modname, modules_analyzed)
  File "/home/jwhur/.pyenv/versions/3.6.9/lib/python3.6/site-packages/pycg/processing/base.py", line 36, in __init__
    with open(filename, "rt") as f:
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 894, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1129, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1273, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1229, in _get_spec
  File "/home/jwhur/.pyenv/versions/3.6.9/lib/python3.6/site-packages/pycg/machinery/imports.py", line 39, in __init__
    ig_obj.create_edge(self.fullname)
  File "/home/jwhur/.pyenv/versions/3.6.9/lib/python3.6/site-packages/pycg/machinery/imports.py", line 87, in create_edge
    raise ImportManagerError("Can't add edge to a non existing node")
pycg.machinery.imports.ImportManagerError: Can't add edge to a non existing node

JaewonHur avatar Jul 20 '22 10:07 JaewonHur

Hey @JaewonHur, I had the same problem and updating python to version 3.10.5 helped me solve it. Not sure if it will in your case though.

amphioxis avatar Aug 09 '22 14:08 amphioxis