Python get site packages location

site — Site-specific configuration hook¶

This module is automatically imported during initialization. The automatic import can be suppressed using the interpreter’s -S option.

Importing this module will append site-specific paths to the module search path and add a few builtins, unless -S was used. In that case, this module can be safely imported with no automatic modifications to the module search path or additions to the builtins. To explicitly trigger the usual site-specific additions, call the site.main() function.

Changed in version 3.3: Importing the module used to trigger paths manipulation even when using -S .

It starts by constructing up to four directories from a head and a tail part. For the head part, it uses sys.prefix and sys.exec_prefix ; empty heads are skipped. For the tail part, it uses the empty string and then lib/site-packages (on Windows) or lib/python X.Y /site-packages (on Unix and macOS). For each of the distinct head-tail combinations, it sees if it refers to an existing directory, and if so, adds it to sys.path and also inspects the newly added path for configuration files.

Читайте также:  Change system python version

Changed in version 3.5: Support for the “site-python” directory has been removed.

If a file named “pyvenv.cfg” exists one directory above sys.executable, sys.prefix and sys.exec_prefix are set to that directory and it is also checked for site-packages (sys.base_prefix and sys.base_exec_prefix will always be the “real” prefixes of the Python installation). If “pyvenv.cfg” (a bootstrap configuration file) contains the key “include-system-site-packages” set to anything other than “true” (case-insensitive), the system-level prefixes will not be searched for site-packages; otherwise they will.

A path configuration file is a file whose name has the form name .pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path . Non-existing items are never added to sys.path , and no check is made that the item refers to a directory rather than a file. No item is added to sys.path more than once. Blank lines and lines beginning with # are skipped. Lines starting with import (followed by space or tab) are executed.

An executable line in a .pth file is run at every Python startup, regardless of whether a particular module is actually going to be used. Its impact should thus be kept to a minimum. The primary intended purpose of executable lines is to make the corresponding module(s) importable (load 3rd-party import hooks, adjust PATH etc). Any other initialization is supposed to be done upon a module’s actual import, if and when it happens. Limiting a code chunk to a single line is a deliberate measure to discourage putting anything more complex here.

For example, suppose sys.prefix and sys.exec_prefix are set to /usr/local . The Python X.Y library is then installed in /usr/local/lib/python X.Y . Suppose this has a subdirectory /usr/local/lib/python X.Y /site-packages with three subsubdirectories, foo , bar and spam , and two path configuration files, foo.pth and bar.pth . Assume foo.pth contains the following:

# foo package configuration foo bar bletch
# bar package configuration bar

Источник

How do I find the location of my Python site-packages directory

  • All categories
  • ChatGPT (11)
  • Apache Kafka (84)
  • Apache Spark (596)
  • Azure (145)
  • Big Data Hadoop (1,907)
  • Blockchain (1,673)
  • C# (141)
  • C++ (271)
  • Career Counselling (1,060)
  • Cloud Computing (3,469)
  • Cyber Security & Ethical Hacking (162)
  • Data Analytics (1,266)
  • Database (855)
  • Data Science (76)
  • DevOps & Agile (3,608)
  • Digital Marketing (111)
  • Events & Trending Topics (28)
  • IoT (Internet of Things) (387)
  • Java (1,247)
  • Kotlin (8)
  • Linux Administration (389)
  • Machine Learning (337)
  • MicroStrategy (6)
  • PMP (423)
  • Power BI (516)
  • Python (3,193)
  • RPA (650)
  • SalesForce (92)
  • Selenium (1,569)
  • Software Testing (56)
  • Tableau (608)
  • Talend (73)
  • TypeSript (124)
  • Web Development (3,002)
  • Ask us Anything! (66)
  • Others (2,231)
  • Mobile Development (395)
  • UI UX Design (24)

Join the world’s most active Tech Community!

Welcome back to the World’s most active Tech Community!

Subscribe to our Newsletter, and get personalized recommendations.

GoogleSign up with Google facebookSignup with Facebook

Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

  • DevOps Certification Training
  • AWS Architect Certification Training
  • Big Data Hadoop Certification Training
  • Tableau Training & Certification
  • Python Certification Training for Data Science
  • Selenium Certification Training
  • PMP® Certification Exam Training
  • Robotic Process Automation Training using UiPath
  • Apache Spark and Scala Certification Training
  • Microsoft Power BI Training
  • Online Java Course and Training
  • Python Certification Course
  • Data Scientist Masters Program
  • DevOps Engineer Masters Program
  • Cloud Architect Masters Program
  • Big Data Architect Masters Program
  • Machine Learning Engineer Masters Program
  • Full Stack Web Developer Masters Program
  • Business Intelligence Masters Program
  • Data Analyst Masters Program
  • Test Automation Engineer Masters Program
  • Post-Graduate Program in Artificial Intelligence & Machine Learning
  • Post-Graduate Program in Big Data Engineering

COMPANY

WORK WITH US

DOWNLOAD APP

appleplaystore googleplaystore

CATEGORIES

CATEGORIES

  • Cloud Computing
  • DevOps
  • Big Data
  • Data Science
  • BI and Visualization
  • Programming & Frameworks
  • Software Testing © 2023 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved. Terms & ConditionsLegal & Privacy

Источник

Where Does pip Install Packages

To see where pip installs packages on your system, run the following command:

And replace with the actual name of the package.

Example: NumPy Location

For example, let’s see where NumPy is installed:

Name: numpy Version: 1.22.2 Summary: NumPy is the fundamental package for array computing with Python. Home-page: https://www.numpy.org Author: Travis E. Oliphant et al. Author-email: None License: BSD Location: /usr/local/lib/python3.8/site-packages Requires: Required-by: torchvision, perfplot, opencv-python, matplotx, DALL-E, benchit

Here you can see that the location field says the package is installed at /usr/local/lib/python3.8/site-packages.

The location obviously depends on your system and Python version.

How to View All pip Package Locations

To list all the installed package locations, run the following command:

This spits out a huge list of different packages and their locations:

alabaster 0.7.8 /usr/lib/python3/dist-packages apparmor 2.13.3 /usr/lib/python3/dist-packages appdirs 1.4.3 /usr/lib/python3/dist-packages apturl 0.5.2 /usr/lib/python3/dist-packages .

Now you understand how to check the pip package locations using the command line/terminal.

Next, let’s take a look at how you can find this information using a Python script.

How to View pip Package Location in Python Script?

In addition to using the command line to figure out the location of packages installed via pip, you can run a Python script to get the information.

There are two ways to do this:

The site Module

To find the general location of pip packages in a Python script:

  1. Import the site package.
  2. Call the getsitepackages() function of the module.
  3. See a list of global package locations.

Here is how it looks in code:

>>> import site >>> site.getsitepackages() ['/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.8/dist-packages']

And to get a user-specific package location as a string, call the getusersitepackages() function instead.

The help() Function

Of course, you can always use the help() function to get all kinds of information about any Python package or object.

This also shows you the location where the package is installed.

For example, lets’ see where the pandas package is installed:

>>> import pandas >>> help(pandas)

Running this piece of code opens up the package-specific manual.

If you scroll all the way down to the end of this output, you can see the FILE section where it shows you the path of the package.

pip install location pandas

By the way, in case you happen to be unfamiliar with the help() function in Python, I highly recommend you read this article. Using help() can help you a lot and save valuable coding time!

About the Author

Hi, I’m Artturi Jalli!

I’m a Tech enthusiast from Finland.

I make Coding & Tech easy and fun with well-thought how-to guides and reviews.

I’ve already helped 5M+ visitors reach their goals!

ChatGPT Review (and How to Use It)—A Full Guide (2023)

ChatGPT is the newest Artificial Intelligence language model developed by OpenAI. Essentially, ChatGPT is an AI-based chatbot that can answer any question. It understands complex topics, like.

10 Best AI Art Generators of 2023 (Reviewed & Ranked)

Choosing the right type of AI art generator is crucial to produce unique, original, and professional artwork. With the latest advancements in AI art generation, you can.

How to Make an App — A Complete 10-Step Guide (in 2023)

Are you looking to create the next best-seller app? Or are you curious about how to create a successful mobile app? This is a step-by-step guide on.

9 Best Graphic Design Courses + Certification (in 2023)

Do you want to become a versatile and skilled graphic designer? This is a comprehensive article on the best graphic design certification courses. These courses prepare you.

8 Best Python Courses with Certifications (in 2023)

Are you looking to become a professional Python developer? Or are you interested in programming but don’t know where to start? Python is a beginner-friendly and versatile.

8 Best Swift & iOS App Development Courses [in 2023]

Are you looking to become an iOS developer? Do you want to create apps with an outstanding design? Do you want to learn to code? IOS App.

Источник

Оцените статью