pip
What is pip?
pip is Python's package tool. The name is built from the words pip installs packages. Packages sit in the PyPI registry. requirements.txt is the project's package list. pip install -r reads that list. Since Python 3.4, pip usually comes with Python. A virtual environment gathers packages inside the project, so another project's version does not mix in. The difference from Python is this: Python runs the file, and pip does not run any program by itself. The difference from Node.js is this too: Node runs JavaScript and does not use pip. Node's package comes with npm. pip is only for Python.
What is pip used for?
pip is for installing a library once and repeating the same list on another computer.
- Installing a ready library into the project
- Keeping the list in requirements.txt
- Separating the version in a virtual environment
- Replacing an old package with a newer one
What can you do with pip?
With pip you download a package, install from the list, and show the installed name. It does not write the Python program itself. A package's code can start with your command. Installing a package you do not know brings that code too.
Is pip hard to learn?
Installing one package is easy. The difficulty is the versions mixing. The pip on the computer may look at another Python. Installing only by hand, without writing the list, does not give the same result on another machine tomorrow. Without a virtual environment, the package falls into the shared place.
Advantages and limits
Advantage: a library is not rewritten, the list stays in one file, and it comes ready with Python. Limit: installing into the wrong Python makes a quiet mistake. Not every small job needs a package. pip is not Python itself.
Basic ideas
A package is ready code. The list says what the project needs. The environment is the separate folder of those packages.
- pip install installs one package
- requirements.txt keeps the list
- venv separates the environment
- PyPI is the shared place of packages
A short example
This command installs the packages in the list. If the list is empty, it downloads nothing.
pip install -r requirements.txt
Common questions
- Are pip and Python the same? No. Python runs the .py file. pip brings that file's library and does not run a program itself.
- Are pip and Node.js the same? No. Node runs JavaScript and does not use pip. Node's package comes with npm. pip is only for Python.
- Is requirements.txt the package itself? No. It is the list of names.