+91 81900 98289

Python PIP

This Python PIP lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

pip installs packages from the Python Package Index into your environment. The command runs in a terminal, not inside a Python file.

A virtual environment keeps those packages off the system Python. Create one before you install a project’s requirements.

Example 1: Start here

This browser runner cannot install packages. Use your own machine for pip.

print("pip install requests") # print writes this; the quotes are not shown print("Run that in a terminal, not with Run on this page.")

Example 2: A requirements line

A requirements file pins a package name and a version. This program only reads that line.

line = "requests==2.32.3" # text name, version = line.split("==") # unpack the values into these names print(name, version) # a comma prints each value, with a space between

Example 3: Skip a comment

Blank lines and comments are not packages.

lines = ["# tools", "requests==2.32.3", ""] for line in lines: # repeat the indented lines once per value if line and not line.startswith("#"): print(line)

Example 4: Why the browser cannot install

The try-it runner has no network install. Use a virtual environment on your machine for pip.

print("Install packages on your computer with: python -m pip install requests") # print writes this; the quotes are not shown
This browser runner cannot install packages. Use your own machine for pip.
Call Now 81900 98289