"What the heck is a module!" A science researcher betrayed by AI, screaming during their first Python experience #57
1. The beginning of the tragedy: AI, the promising newcomer, and then an error

"Improve work efficiency!" "Data analysis!" "Generative AI!"
It's been all the buzz lately, hasn't it?
Even though I have a science background, I was ananalog researcherwho had nothing to do with programming.
I'm the type who relied on Excel to endlessly repeat measurements and experiments for my research.
However, determined to keep up with the times, I decided to ask AI to help improve my work.
"Alright, AI! Give me somePython codethat I can use right now!"
The AI lived up to my expectations and gave me shiny, new code in no time.
"W-wow, this is the future...! Now my research data processing will be done in an instant...!" ✨
I excitedly copied and pasted it, and went to run it!
# AIからもらった魔法のコード(と信じていた)
import pandas as pd
# 以下、華麗なデータ処理の記述……
What appeared on the screen wasn't a sparkling future, butpitch-black despair.
ModuleNotFoundError: No module named 'pandas'
💥"No module named XX"💥
What the heck! What's a module!
Why won't it run!
I thought I had finally escaped thenightmarish realm of environment setup, but that was short-lived.
Yes, there waseven more darknessahead.
Even as a science person, programming is a distant world. The text in front of me looked like nothing butspells.
Plus, I'm not good at English.
I could only read this error message as"I don't know what you're talking about."
2. Common beginner mistake: Why does AI code become a "defective product"?

"Just look at the web and copy-paste it, and it'll work!" smiles the sparkling AI.
......No, no, it doesn't work.
They assume that "having the libraries installed is a given."
It's like buying the latest smartphone and assuming thatevery single appis pre-installed from the start.
But in reality, it'scompletely empty.
The words that come out look like Japanese, but they aren't Japanese.
My inner voice is saying, "I don't know what you're talking about!"
Yes, the AI is outputting code under the assumption that "convenient additional features = libraries" are already installed.
In other words,if your PC is "bare-bones," it will absolutely not run as is.
This is the true identity of why "AI code = defective product?"

Yes, the AI is outputting code under the assumption that"convenient additional features = libraries"are already installed.
In other words, if your PC is "bare-bones," it will absolutely not run as is.
This was the true identity of what looked like"AI code = defective product?"
Lost, and a divine word from a junior colleague

Modules, libraries, pip...
...Yeah, I still don't get it.
My pride as a science researcher crumbles before this absolute basic wall.
"Can someone explain this in a way that's easy to understand?" I lament.
Then, my junior colleague listening next to me smirks.
"Why not just ask the AI again? lol"
――Th-that's it! The counter-intuitive idea of relying once more on the one who betrayed you first!
3. The AI taught me! The "Three Sacred Treasures" of the Python world

I muster the courage to ask the AI that betrayed me for the first time again! This time, the AI carefully taught me these "Three Sacred Treasures".
If you understand this, you can take a step forward as a new programmer in the AI era.
① Library: "A pack of super-efficient additional features"
Image: Think of it as an "app itself" like Word or Excel. It's a collection of useful features, such as 'pandas' for data analysis or 'NumPy' for calculations.
Role: Saves you the trouble of building from scratch.
② pip: "The clerk in charge of installation"
Image: Think of it as an App Store clerk for iPhone. Unless you talk to this clerk, the library (app) won't enter your PC.
Role: To "install" libraries onto your PC.
③ import: "The spell to declare 'I'm going to use this' within the program"
Image: A start button that declares, "Okay, I'm launching this app now!"
Role: To "call" an installed library so it can actually be used within the program.
4. Rapid growth step: The "two rituals" to run AI code
To run the code I got from the AI, I only needed to take these two steps, "pip → import", at the beginning.
Step 1: First, install the library (Clerk, please!)
Recite this spell in the terminal (the black screen).
pip install pandasWith this, the library will be "installed" on your PC.
Now the "app itself" is loaded!
Step 2: Next, call it within the program (Start!)
Go back to the beginning of the AI code and leave this spell as it is.
import pandas as pdThis allows you to use the installed pandas under the nickname 'pd'. Now you can launch the app from the "shortcut icon"!
If you don't know these two steps of "installing with pip, then calling with import", the code won't work no matter how brilliant the AI is.
This is the first wall that business people in the AI era must overcome, and one that anyone can overcome!
5. Screaming is a sign of growth!

Remember that moment when you were frustrated because the AI code wouldn't run.
You were never wrong.
"What is a library?!"
"Why won't the AI explain it to me?!"
—That scream was proof that you had stepped into the new world of Python.
Having learned "pip install," I am no longer just an analog researcher. I am finally a primate who has grasped the tool called Python.
I am a "master of the AI era" who possesses the power to turn AI magic into reality with my own hands.
Ultimate Technique: Running away is winning
...Huh?Compatibility with versions or virtual environments aren't explained?
I didn't worry about such trivial details and quietly escaped to Google Colab, so what of it? lol
At first, you should just enjoy the fact that it works!
Peace of mind over perfect environment setup.
This was the first conclusion I reached.
【Next Growth Challenge】
Once the errors disappear, you'll likely run into questions like "What is 'pd'?" and "How many libraries are there?" next.
Your intellectual curiosity is moving to the next stage!
If you thought "That's so relatable!" while reading this article, please support me with a like and a follow!🙌
And after this, having reached my "first love" with Jupyter Notebook, even more intense drama awaited me...
Related Articles
いいなと思ったら応援しよう!
よろしければ応援お願いします! いただいたチップはクリエイターとしての活動費に使わせていただきます!