Python’s package manager is called pip
, and it comes bundled with every recent version of Python. pip
allows us to install packages that don’t come bundled with the Python standard library.
By default, pip
searches what’s called PyPI, or the Python Package Index. This public repository contains thousands of packages written by the Python community.
This lesson shows you how to use pip
to download the requests
package from PyPI. This package allows you to conveniently send HTTP requests with Python:
import requests
url = 'https://www.google.com'
response = requests.get(url)
print(f'Response returned: {response.status_code}, {response.reason}')
print(response.text[:200])
Packages can be installed with pip install
. To view a full listing of commands, run pip help
.
pip list
will show you a list of all the currently installed packages. pip show
will show you more information about a package, including packages it requires (dependencies) as well as packages that require it (packages it is a dependency of).
The following command string can be used with conda
to create a new, minimal virtual environment called web-parser
:
$ conda create --name web-parser python --no-default-packages
You can also specify a custom python version:
$ conda create --name web-parser python=3.6 --no-default-packages
To ensure that you only pip
install safe, effective packages, check out How to Evaluate the Quality of Python Packages.
kethan on Sept. 19, 2020
pip
command is not installed in Python