SMAT-Lab / Scalpel

Scalpel: The Python Static Analysis Framework
Apache License 2.0
295 stars 46 forks source link

Fail to import CallGraphGenerator #122

Closed Table-the-cat closed 9 months ago

Table-the-cat commented 9 months ago

I try to use from scalpel.call_graph.pycg import CallGraphGenerator to import CallGraphGenerator but it throws an error ModuleNotFoundError: No module named 'pycg'

Traceback (most recent call last):
  File "D:\Work\pyCharm\pythonProjects\scalpelTest\main.py", line 1, in <module>
    from scalpel.call_graph.pycg import CallGraphGenerator, formats
  File "D:\Work\Python\lib\site-packages\scalpel\call_graph\pycg.py", line 9, in <module>
    from pycg.pycg import CallGraphGenerator as CallGraphGeneratorPyCG
ModuleNotFoundError: No module named 'pycg'

The version of PyCG is 0.0.8

Jarvx commented 9 months ago

Hi, thanks for your interest. Scalpel is dependent on pycg 0.0.6 as indicated here https://github.com/SMAT-Lab/Scalpel/blob/main/requirements.txt.

Table-the-cat commented 9 months ago

Hi, thanks for your interest. Scalpel is dependent on pycg 0.0.6 as indicated here https://github.com/SMAT-Lab/Scalpel/blob/main/requirements.txt.

Thanks for replying, I solved this problem but a new error occur

Traceback (most recent call last):
  File "D:\Work\pyCharm\pythonProjects\scalpelTest\scal.py", line 1, in <module>
    from scalpel.call_graph.pycg import CallGraphGenerator
  File "D:\Work\Python12\Lib\site-packages\scalpel\call_graph\pycg.py", line 13, in <module>
    import packaging
ModuleNotFoundError: No module named 'packaging'

Sorry I am a beginner. Is this means my dependencies are not complete or just another version incorrect?

Jarvx commented 9 months ago

can you give the full list of your locally installed package information? You can use pip list

v587su commented 9 months ago

I have the same problem. Fixed it by downgrading PyCG from 0.0.8 to 0.0.6

Table-the-cat commented 9 months ago

can you give the full list of your locally installed package information? You can use pip list

here is my list: astor 0.8.1 astunparse 1.6.3 dataclasses 0.6 graphviz 0.20.1 importlib-resources 6.1.1 networkx 3.2.1 pip 23.2.1 pycg 0.0.6 python-scalpel 1.0b0 regex 2023.12.25 setuptools 69.0.3 six 1.16.0 typed-ast 1.5.5 typeshed-client 2.4.0 wheel 0.42.0

Table-the-cat commented 9 months ago

I have the same problem. Fixed it by downgrading PyCG from 0.0.8 to 0.0.6

I have already downgraded PyCG to 0.0.6 but occured the error No module named 'packaging' as I said above

Jarvx commented 9 months ago

I have the same problem. Fixed it by downgrading PyCG from 0.0.8 to 0.0.6

I have already downgraded PyCG to 0.0.6 but occured the error No module named 'packaging' as I said above Please refer to here and see if the issue can be fixed https://pypi.org/project/packaging/

Table-the-cat commented 9 months ago

I have the same problem. Fixed it by downgrading PyCG from 0.0.8 to 0.0.6

I have already downgraded PyCG to 0.0.6 but occured the error No module named 'packaging' as I said above Please refer to here and see if the issue can be fixed https://pypi.org/project/packaging/

Thanks, now it seems that the CallGraphGenerator has been imported. I refer this paper to generate a call graph https://www.researchgate.net/publication/358846483_Scalpel_The_Python_Static_Analysis_Framework But occur a new error here is my code:

from scalpel.call_graph.pycg import CallGraphGenerator
cg_generator = CallGraphGenerator(["main.py"], "D:\\Work\\pyCharm\\pythonProjects\\testProject")
cg_generator.analyze()

and here is the full error log:

Traceback (most recent call last):
  File "D:\Work\pyCharm\pythonProjects\scalpelTest\scal.py", line 3, in <module>
    cg_generator.analyze()
  File "D:\Work\Python12\Lib\site-packages\pycg\pycg.py", line 155, in analyze
    self.do_pass(PreProcessor, True,
  File "D:\Work\Python12\Lib\site-packages\pycg\pycg.py", line 144, in do_pass
    self.import_manager.install_hooks()
  File "D:\Work\Python12\Lib\site-packages\pycg\machinery\imports.py", line 207, in install_hooks
    loader = get_custom_loader(self)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Work\Python12\Lib\site-packages\pycg\machinery\imports.py", line 34, in get_custom_loader
    class CustomLoader(importlib.abc.SourceLoader):
                       ^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'abc'. Did you mean: '_abc'?
Table-the-cat commented 9 months ago

I have the same problem. Fixed it by downgrading PyCG from 0.0.8 to 0.0.6

I have already downgraded PyCG to 0.0.6 but occured the error No module named 'packaging' as I said above Please refer to here and see if the issue can be fixed https://pypi.org/project/packaging/

Thanks, now it seems that the CallGraphGenerator has been imported. I refer this paper to generate a call graph https://www.researchgate.net/publication/358846483_Scalpel_The_Python_Static_Analysis_Framework But occur a new error here is my code:

from scalpel.call_graph.pycg import CallGraphGenerator
cg_generator = CallGraphGenerator(["main.py"], "D:\\Work\\pyCharm\\pythonProjects\\testProject")
cg_generator.analyze()

and here is the full error log:

Traceback (most recent call last):
  File "D:\Work\pyCharm\pythonProjects\scalpelTest\scal.py", line 3, in <module>
    cg_generator.analyze()
  File "D:\Work\Python12\Lib\site-packages\pycg\pycg.py", line 155, in analyze
    self.do_pass(PreProcessor, True,
  File "D:\Work\Python12\Lib\site-packages\pycg\pycg.py", line 144, in do_pass
    self.import_manager.install_hooks()
  File "D:\Work\Python12\Lib\site-packages\pycg\machinery\imports.py", line 207, in install_hooks
    loader = get_custom_loader(self)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Work\Python12\Lib\site-packages\pycg\machinery\imports.py", line 34, in get_custom_loader
    class CustomLoader(importlib.abc.SourceLoader):
                       ^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'abc'. Did you mean: '_abc'?

I refer this to fix it temporally https://github.com/vitsalis/PyCG/issues/15#issue-1085249945