Linux find python packages

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.

Источник

Where Are Python Packages Installed in Linux

By reading this tutorial, you will learn where the Python packages and modules are installed in your system and other Linux distributions. But the most important teaching in this tutorial is in the last section, where you will learn how to find the Python packages without memorizing the directories independently of the Linux distribution or installation method.

All examples shown in this article include screenshots, making it easy for every Linux user to understand them independently of their knowledge level.

Previous Necessary Step: Learning the Installed Python Version

To follow all instructions described in this article, you must first know the Python version installed in your system.

To learn it, you can use the ls command followed by the executable files path and replace the version with a wildcard as shown in the following:

As you can see, there are two Python versions currently installed in my system: Python 3.9 and Python 2.7. The other paths belong to the symbolic links.

Читайте также:  Centos change java version

Where Are Python Packages Stored When Installed Without Packages Manager

If the Python installation was done from sources or from Python installation mechanisms (like easy_install or Python setup.py) and not from a packages manager like apt-get or aptitude among others, Python packages are stored under the /usr/local/lib/python/ directory.

This directory can be defined as universal and valid for almost every Linux distribution because it’s based on installation methods available for different distributions independently of their package managers. Of course, this is not valid when Python is installed using a specific distro packages manager.

If you compiled Python from sources or installed it using the setup.py or easy_install, you can check this location using the ls command as shown in the following screenshot where 3.10 must be replaced with your actual Python version.

Where Are Python Packages When Installed Through Pip

Python packages installed using the pip command are stored under the /usr/local/lib//dist-packages/pip/ directory.

You can find the correct location by using the pip command followed by the list option as shown in the following:

Where Are Python Packages Installed in Debian/Ubuntu Distributions

If you are a Debian, Ubuntu, or other based distribution and you installed Python through the dpkg packages manager or one of its frontends like apt-get, apt or aptitude, the packages are stored in the /usr/lib/python directory, as shown in the following image where 3.9 must be replaced with your actual Python version.

Note: As mentioned previously, if you don’t install Python using the dpkg, apt, apt-get or aptitude, the packages will have a different location described in the first section of this document.

Where Are Python Packages Installed in Red Hat Based Distributions & SUSE

Like in Debian/Ubuntu, Python packages without defined specific architecture are installed under the /usr/lib/python directory.

But specific architecture Python packages in Red Hat are stored under a descriptive directory like /usr/lib64/python .

Local Python packages are installed under /home//.local/lib/python/.

How to Find Installed Python Packages Independently of the Installation Method

Whatever is your Linux distribution, you can always use the find command to search the files by type, in this case to find the Python packages using its .py extension as shown in the following figure where /usr is the parent directory in the recursive search, -type f defines that you are searching files and not directories, and “*.py” is the extension of files that you are looking for.

Finding Python Modules

To find the Python modules, open the Python console by executing the python, where must be replaced with your actual Python version. Then, run the command help(“modules”) as shown in the following example:

In our case, using the Python 3, we execute the following code:

Then, we also execute this following code:

Conclusion

As you can see, Python packages are installed in different locations depending on the Linux distribution, installation methods, and in some cases, depending on the architecture. But the find command is useful to search all Python packages independently of the installation method, distribution, or architecture, and is a valid technique for every Linux distribution. Learning the program versions or how to find the files by type or extension is extremely easy and mandatory for all the Linux users independently of their knowledge level. It is important to clarify that while this article provides examples including Python 2, this version was discontinued and Python 3 is the current version, with many improvements. Always try to install Python using your Linux distribution packages manager, automatically resolving the dependencies and easing the removal process before problems.

Thank you for reading this article. We hope it was useful. Keep following Linux Hint for more professional Linux tips and tutorials.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.

Источник

Where Are Python Packages Installed

Where Are Python Packages Installed

  1. Use the pip Command to List the Packages Installed
  2. Use the conda Command to List the Locally Installed Packages
  3. Use the python Command to List the Packages Installed
  4. Use the distutils.sysconfig Module to List the Packages Installed
  5. Use the sysconfig Module to List the Packages Installed

A package in Python can be defined as a directory that contains Python files. These files are usually Python Modules.

As the program grows larger and gets more complex, similar modules are positioned in a package, which helps in making the program easier to manage and have better readability. This approach is often called Modular Programming, and packages help in achieving it.

The file __init__.py must be contained inside the directory in order for Python to consider it as a Package. This file usually has the initialization code for the package, but it can be left empty.

This tutorial will discuss different methods to find the directories in which python packages are installed.

Use the pip Command to List the Packages Installed

In Python, the packages can be installed both globally and locally.

A package, when installed globally, is available to all the users in the system. The same package, when installed locally, would only be available to the user that manually installed it.

By default, the pip command installs the packages globally.

The following code uses the pip command to list the packages installed globally.

# we can also use "pip list command" pip freeze 

Although, by default, the pip command installs packages globally, the packages that have been manually installed locally can also be seen using this command.

The following code uses the pip command to list the packages installed locally.

# we can also use "pip list --user" pip freeze --user 

Use the conda Command to List the Locally Installed Packages

This method works only for programmers working on Anaconda IDE. It is possible to list the locally installed package in a conda environment. To execute this, we just have to write a single line of code in the Anaconda prompt.

Источник

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