GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Locate Python site-packages - w3resource

Python: Locate Python site-packages

Last update on May 17 2025 05:44:11 (UTC/GMT +8 hours)


Python Site Packages Locator

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 the 'site' module.
import site

# Use the 'site.getsitepackages()' function to retrieve site packages' paths.
# 'site.getsitepackages()' returns a list of paths where site packages are installed.
print(site.getsitepackages())

Sample Output:

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

Explanation:

The above Python code imports the ‘site’ module and then calls the getsitepackages() function.

By calling print(site.getsitepackages()), the code will print a list of these paths to the console output. This can be useful for understanding where Python packages are installed on a particular system, which can be important for managing dependencies in Python projects.

For more Practice: Solve these Related Problems:

  • Write a Python script to list all installed Python packages along with their versions.
  • Write a function that finds the location of a specific installed Python package.
  • Write a script to check if a particular package is installed and return its path.
  • Write a Python program that determines the default Python module search paths.

Go to:

  • Python Basic Exercises Home ↩
  • Python Exercises Home ↩

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.

Python Code Editor:

 

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.