Skip to Content
Course content

7: Setting Up PyCharm for Python Development

Click on the "Edit" button in the top corner of the screen to edit your slide content.

Up until now, we've been keeping things simple. But as your projects grow, you'll find that a basic text editor just doesn't cut it. You need an Integrated Development Environment (IDE). I use PyCharm because it essentially acts as a second brain—it catches your typos before you even run the code and handles the messy parts of environment management so you don't have to.

To show you how to actually get this thing configured, we're going to build a quick Currency Converter. This isn't just about the code; it's about setting up the "plumbing" that allows the code to run reliably on your machine and anyone else's.

Creating a dedicated space for our Currency Tool

When I start a new project, the first thing I do is isolate it. I don't want a library I install for this project to break something I built six months ago. In PyCharm, this happens right at the start.

  • Open PyCharm and hit New Project.
  • I'm naming this one currency_converter.
  • Under "Python Interpreter," make sure New environment using Virtualenv is selected. This creates a private folder inside your project where all your dependencies live. It's a lifesaver.

Telling PyCharm which Python to use

Once the project opens, you'll see a folder structure on the left. Right-click the project root and create a new Python file called converter.py. Now, for this tool to work, we need to fetch real-time exchange rates from the web, which means we need the requests library.

I'll start typing the code immediately:

import requests

def get_exchange_rate(base, target):
    url = f"https://api.exchangerate-api.com/v4/latest/{base}"
    response = requests.get(url)
    data = response.json()
    return data['rates'][target]

amount = 100
rate = get_exchange_rate("USD", "EUR")
print(f"{amount} USD is {amount * rate} EUR")

Handling the 'ModuleNotFoundError' hiccup

Here is where I usually trip up if I'm moving too fast. I just hit the green "Run" button, and—surprise—I get a massive red error: ModuleNotFoundError: No module named 'requests'.

What happened? I created the virtual environment, but I didn't actually install the library into that environment. I often forget that a fresh venv is completely empty. Instead of jumping to the terminal, I'll use PyCharm's built-in manager. I'll go to File > Settings > Project: currency_converter > Python Interpreter. I see the list is empty, so I'll click the + icon, search for requests, and hit Install Package. Now, the red squiggly line under the import statement disappears. That's the "magic" of the IDE.

Firing up the code and testing the flow

Now that the environment is healthy, I'm not just going to run it and hope for the best. I'm going to use a breakpoint. I'll click in the gutter next to the line data = response.json() to place a red dot. Then, instead of clicking "Run," I'll click the Debug icon (the little bug).

The program pauses right there. I can hover my mouse over response and see exactly what the API sent back before the code even processes it. This is how professional engineers spend 80% of their time—not writing code, but observing it while it runs to make sure the data is what they expect.




📋 Practical Task

Build a System Info Monitor with a Custom PyCharm Environment

Your task is to set up a new PyCharm project from scratch that monitors your computer's basic system stats. This will test your ability to manage a virtual environment and install external dependencies.

  • Create a new project named sys_monitor using a Virtualenv.
  • Install the psutil library using the PyCharm Python Interpreter settings.
  • Create a file named monitor.py and write a script that prints the current CPU percentage and available memory.
  • The Challenge: Set a breakpoint on the line where you retrieve the memory stats, run the program in Debug mode, and use the "Variables" window to inspect the raw value returned by psutil before it is printed.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.