Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to list all packages that are being used in python script?

I want to check all the packages that are being used by my python script. I have a list of imports at the top of the script, but I’m not sure if those packages are actually getting used. So I want to check, of all the commands/functions I am using within by script, which of my imports are being used.

For example in the sample below I am only using the pandas package but I am importing numpy as well:

import pandas as pd
import numpy as np

data = pd.read_csv("/path/to/file.csv")

I want to be able to get back a result of just pandas since that is the only package that is getting used.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

All the solutions I’ve seen will just get all the packages that are imported.

>Solution :

Use vulture to find unused imports. Install it:

pip install vulture
vulture your_script.py
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading