Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find which python modules are being imported

Tags:

python

package

What's an easy way of finding all the python modules from a particular package that are being used in an application?

like image 469
John Jiang Avatar asked Jan 04 '10 04:01

John Jiang


People also ask

How can I tell which Python modules are imported?

Python modules can get access to code from another module by importing the file/function using import.

How can I tell where Python is importing from?

Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to know the location of built in modules.

How do I identify a Python module?

We can also use the inspect module in python to locate a module. We will use inspect. getfile() method of inspect module to get the path. This method will take the module's name as an argument and will return its path.

How do you find where my Python modules are installed?

Usually in /lib/site-packages in your Python folder. (At least, on Windows.) You can use sys. path to find out what directories are searched for modules.


1 Answers

sys.modules is a dictionary mapping module names to modules. You can examine its keys to see imported modules.

See: http://docs.python.org/library/sys.html#sys.modules

like image 86
Ned Batchelder Avatar answered Oct 08 '22 20:10

Ned Batchelder