w3resource

Python: Locate Python site-packages

Python Basic: Exercise-44 with Solution

Write a Python program to locate Python site-packages.

site.getsitepackages(): Return a list containing all global site-packages directories.

Sample Solution:

Python Code:

import site; 
print(site.getsitepackages())

Sample Output:

['/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.5/dist-packages
']

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to get OS name, platform and release information.
Next: Write a python program to call an external command in Python.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Try-catch-else construct:

try:
  foo() 
except Exception: 
  print("Exception occured")
else:
  print("Exception didnt occur")
finally:
  print("Always gets here")