Python Package Management
Pip makes our lives easier! Python can import additional modules. This extends Python functionality without us having to write all the code ourselves.
There are some modules built into Python. For example, you can use import time, and you can immediately use it in your script.
But there are other modules too, that don’t come ‘out of the box’ with Python. And this is what we use pip for.
If you’re familiar with Linux, you’ll feel very comfortable here. In Linux, you can use commands like apt-get to install extra software. That’s what pip does for Python. It’s like the app store you have on your phone, but for Python packages.
A package contains all the files that you need for a new module to work. One module may rely on another module. This is a dependency. When you install the package, you also install the module’s dependencies.
Pip Version
You can simply use the pip command. If that doesn’t work, you can also use it within Python. This follows the format python -m pip …
When Python was installed, it’s almost certain that pip was also installed. You can check if this is the case by checking the version:
C:\>pip --version pip 21.3.1 from C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip (python 3.10)
If you need to upgrade, you can use python -m pip install –upgrade pip. This will automatically download the newest version (pip itself is a package) and install it:
C:\>python -m pip install --upgrade pip Requirement already satisfied: pip in c:\program files\windowsapps\pythonsoftwarefoundation.python.3.10_3.10.496.0_x64__qbz5n2kfra8p0\lib\site-packages (21.2.4) Collecting pip Downloading pip-21.3.1-py3-none-any.whl (1.7 MB) |████████████████████████████████| 1.7 MB 3.3 MB/s Installing collected packages: pip Successfully installed pip-21.3.1
Pip Packages
You can get a list of packages that are installed. In the example below, pip sees itself as a package. I have also previously installed the requests package, which installed four other dependencies.
C:\>pip list Package Version ------------------ --------- certifi 2021.10.8 charset-normalizer 2.0.9 idna 3.3 pip 21.3.1 requests 2.26.0 urllib3 1.26.7
If you would like to see a list of packages that you can install, you can search or browse the pypi website. Last time I looked, there were nearly 350,000 projects!