Linux find python packages

Where does pip install its packages?

and Django successfully downloaded. Now, I want to open up the Django folder. Where is the folder located? Normally it would be in «downloads», but I’m not sure where it would be if I installed it using pip in a virtualenv.

Can the directory in which to install packages be overridden via CLI args, environment variables or a config file?

LOL. Well, @AndersRuneJensen in the 4 years it took you to answer my question, my Python Fu has improved significantly. I wish I’d remembered I posted this adorable question and come to answer it myself but you beat me to it! Thank you, though, for not answering a very naive question rudely. +1 to you , sir!

10 Answers 10

pip show will provide the location for Windows and macOS, and I’m guessing any system. 🙂

> pip show cvxopt Name: cvxopt Version: 1.2.0 . Location: /usr/local/lib/python2.7/site-packages 

i’m using python 3.6 on windows and «pip» refers to pip for python 3. i don’t need to specify «pip3».

pip list -v can be used to list packages’ install locations, introduced in https://pip.pypa.io/en/stable/news/#b1-2018-03-31

Show install locations when list command ran with “-v” option. (#979)

>pip list -v Package Version Location Installer ------------------------ --------- -------------------------------------------------------------------- --------- alabaster 0.7.12 c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip apipkg 1.5 c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip argcomplete 1.10.3 c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip astroid 2.3.3 c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip . 

This feature is introduced in pip 10.0.0b1. On Ubuntu 18.04 (Bionic Beaver), pip or pip3 installed with sudo apt install python-pip or sudo apt install python3-pip is 9.0.1 which doesn’t have this feature.

Источник

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.

Читайте также:  Abbyy finereader linux аналог

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.

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 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.

Источник

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