Packages that do not exist
Why it matters One wrong letter in an install command can run a stranger's code on your laptop and your build server. The check is a set lookup.
The assistant output in this lesson was written for the course in the exact shape real assistants produce. It is not a recording of any particular model.
Your team keeps a list of the packages it already uses and trusts (INDEX), and a shorter list of the most popular ones (POPULAR). Before anyone runs code from an assistant, a small tool reads the answer and lists every package it names that is not on the trusted list (an invented name is the slopsquatting risk), and flags the ones one slip from a popular package (the typosquatting risk).
The worked example
Install what you need:
```bash
pip install requests==2.32.3 pandas[excel] requets fastjsonschema-pro
```
```python
import os, json
import yaml
from sklearn.linear_model import LogisticRegression
import pdfmagic_extract as pdf
from . import utils
```
Here requests, pandas, os, json, yaml (the package pyyaml) and sklearn (the package scikit-learn) are fine. requets is missing and one letter from requests; fastjsonschema-pro and pdfmagic-extract are missing too; from . import utils is your own code.
Write check_packages(answer, index, popular). answer is the assistant's text. Return {"missing": [...], "lookalikes": [...]}, both sorted, with every name written the standard way: lower case, with any run of -, _ or . turned into one -. Names an answer gives: on a line that starts (after spaces) with pip install, pip3 install or python -m pip install, every word after it, except options (words starting with -) and the file after -r, -c or -e; cut each word at the first [ = < > ! ~ ;. On a line starting with import, each comma-separated module (drop as ...); on a line starting with from X import, module X, unless it starts with a dot. For a module, use the part before the first dot; skip it if it is in sys.stdlib_module_names; if it is in IMPORT_NAMES (given), use the package name there instead. missing: named packages whose standard name is not the standard name of anything in index. lookalikes: missing names exactly one edit (one letter added, removed or changed) from the standard name of a package in popular.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.