My task is to write a function that takes the name of the file and analyzes it and outputs all the non-standard libraries that it uses. And I can't use non-standard libraries to write a script.Example:
import sys
from modulefinder import ModuleFinder
finder = ModuleFinder(['file_test_me.py'])
finder.run_script('file_test_me.py')
result = set(finder.badmodules.keys())
exclude = result - sys.modules.keys()
print(exclude)
file_test_me.py:
import os
import pytest
from numpy import matrix
def something():
import math
import scipy
import pandas as pd
import importlib
module = importlib.import_module('sklearn')
dir(module)
The result I want to get from 1 script is: {'scipy', 'numpy', 'pandas', 'pytest', 'sklearn'}, but I don't get sklearn in this list.