Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a python library? [closed]

Tags:

python

Sorry for such a basic question, I couldn't really find an answer through google that I could understand.

What exactly is a python library in laymans terms? It seems like its something that you download or import and move into a certain folder to add a specific functionality in python?

If I download a library for python, does it go in /usr/lib ?

Any help would be appreciated I'm really lost on this!

like image 478
david Avatar asked Aug 27 '13 20:08

david


People also ask

What is a Python library in simple terms?

A Python library is a collection of related modules. It contains bundles of code that can be used repeatedly in different programs. It makes Python Programming simpler and convenient for the programmer. As we don't need to write the same code again and again for different programs.

What's a Python library?

Python library is a collection of modules that contain functions and classes that can be used by other programs to perform various tasks.

Are Python libraries open source?

Python is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use.

Where do Python libraries go?

Usually the Python library is located in the site-packages folder within the Python install directory, however, if it is not located in the site-packages folder and you are uncertain where it is installed, here is a Python sample to locate Python modules installed on your computer.


1 Answers

In Python, the term "library" is most commonly used when referring to the Standard Library. The Standard Library comes with Python and is installed along with it, making its modules reliably available to any Python code. "Libraries" of code in the more general sense have more specific names in Python.

Modular components of code that can be imported into your Python code are referred to as modules. The Python Standard Library is itself an extensive curated collection of well-documented modules. Modules consist of Python (and sometimes compiled binary) code; they are packaged into zip archives known as packages, along with metadata, installation parameters, test code, etc.

Packages are the files which are downloaded and installed by installers. easy_install and, better, pip, are the two most common package installers. These are user-friendly command-line utilities.

To install a package, for example sh, you would do

$ pip install sh

Depending on your operating system, you may want to prefix that command with sudo; otherwise, I believe you will end up just installing the module for your own use rather than in a system-wide capacity.

See the INSTALLATION section below for info on how to get pip running.

Packages serve to provide a vehicle for installation, testing, usage, and maintenance of the source code which modules consist of. A complex package may include multiple modules. Some packages will install command-line utility scripts in e.g. /usr/bin that use the module code.

Packages are usually (if they are mature enough for widespread use) distributed through the Python Package Index. This is where pip goes to find and download the package.

If you are looking for a piece of code to do some particular thing, try searching for it on PyPI. You can also use $ pip search '*text to search for in package descriptions*'. It will search the PyPI database for you and display the results.

INSTALLATION

As mentioned above, there are two different command-line utilities which provide convenient ways to download and install Python packages. pip is the better of the two, and requires that you have the setuptools package installed. easy_install, the other utility, is installed as part of setuptools.

Installing the setuptools package

Instructions on installing setuptools are provided as part of the package documentation on PyPI. Basically you download the file ez_setup.py and run it:

$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python

Installation of pip is similarly straightforward, once you've got setuptools installed:

$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ [sudo] python get-pip.py
like image 126
intuited Avatar answered Oct 25 '22 16:10

intuited