Why Does My Python Script Keep Asking for Libraries I Never Installed?

Share
Why Does My Python Script Keep Asking for Libraries I Never Installed?

You ran your script and got an error. Something like "ModuleNotFoundError: No module named 'pandas'" or "No module named 'requests'." You did not ask for pandas or requests. You do not know what they are. Your script worked fine in the ChatGPT window when the AI showed it to you. Now suddenly it is demanding things you have never heard of and refusing to run without them.

Here is exactly what is happening and how to fix it in about sixty seconds.

Your Script Is Like a Recipe That Calls for a Spice You Do Not Have

When ChatGPT, Claude, or Gemini writes you a Python script, it does not write every single instruction from scratch. That would take thousands of lines of code for even a simple task.

Instead it uses libraries — collections of pre-written code that handle common tasks. Think of them like spice blends. Instead of grinding and mixing every individual spice from raw ingredients, a good recipe just says "add one teaspoon of garam masala." The spice blend already exists. You just need to have it in your cupboard.

A Python library works the same way. Instead of writing code to send an email from scratch, the script just says "import smtplib" — use the email-sending library. Instead of writing code to read a spreadsheet from scratch, it says "import pandas" — use the spreadsheet library.

The problem is that these libraries are not automatically in your cupboard. They need to be installed on your machine before the script can use them.

Why the AI Did Not Warn You About This

When the AI writes your script inside a chat window, it is not actually running the code. It is writing it. It has no way of knowing what is or is not installed on your specific computer.

So it writes a perfectly correct script that uses the right libraries for the job, hands it to you, and assumes you either know to install them or will figure it out. For a first-timer, that missing step is invisible until the script breaks and the error message sends you down a rabbit hole of unfamiliar words.

How to Install a Missing Library

It is one line in your terminal. Type:

pip install pandas

Replace pandas with whatever library name appeared in your error message. Press enter. Your computer will go and fetch it, install it, and confirm when it is done. The whole thing takes about ten seconds.

pip is Python's built-in package installer. It comes with Python automatically. Think of it as an app store for Python libraries — you tell it what you want, it finds it and installs it.

If your script needs multiple libraries, install them one by one. Or paste your error message back to the AI and ask "what do I need to install to make this run?" It will give you the exact commands.

The Lines at the Top of Your Script Are a Shopping List

Every line at the top of your script that starts with import is the script telling you what it needs. Before you run anything for the first time, scroll to the top of your script and look at those lines.

import pandas
import requests
import smtplib

Each one of those is a library that needs to be installed. Run pip install for each one before you try to run the script and you will avoid most of the errors that catch first-timers out.

The One Thing to Remember

A library is just a collection of pre-written code your script borrows to get things done faster. When it is missing, your script stops and tells you. The fix is always the same: pip install followed by the library name. Ten seconds. Done.


Ready to run yours without the setup headaches? → Snapdock

New here? This might help: Python errors. What your computer is actually trying to tell you. →