Brandon
Brandon

Reputation: 361

Where are python modules stored?

I'm new to this and wondering, where's all the code for the modules and packages and stuff that you can import located on my computer.

Can anyone give me a short lesson and help me out?

Upvotes: 4

Views: 3953

Answers (1)

Himanshu Mishra
Himanshu Mishra

Reputation: 9456

Suppose you want to know the location of xyz module. You do this on the interpreter

>>> import xyx
>>> xyz.__file__

You'll get the location of the pyc file from where your module is being imported.

You can also simply do

>>> xyz

to get the module name and the location of the module.

To know about all the possible locations from where the modules are imported, use sys.path:

>>> import sys
>>> sys.path

This will give you the list of the locations where Python searches for a module when you do import.

Hope that helps.

Upvotes: 5

Related Questions