Working on Your Own Computer
Learning Objectives
- You can explain what the filesystem is and what a path identifies.
- You can install PyCharm and set up Python so that you can run a script.
- You can create or open a project in PyCharm and edit a Python file.
- You can navigate the terminal to a folder and run a Python program there.
- You can explain what the working directory is and why it matters for files.
This chapter is different from the rest of the part. It is mostly setup — installing one program, opening a window, typing a few commands — rather than programming. There is no new Python syntax in it. But after this chapter, your project leaves the sandbox and runs on your own machine, and every chapter after this one assumes that.
If you already have PyCharm installed with a working Python interpreter and have used a terminal before, skim this chapter to check that your setup matches what the course expects, then move on.
The Filesystem, From the Ground Up
If most of your computer use has been through web pages and apps, you may not have spent much time thinking about where files live on your computer. This section is a short orientation. Even if you already know this, the vocabulary matters for the rest of the part.
Your computer stores files in a filesystem: a structure of nested folders (also called directories) that contain other folders or files. Each file has a name and usually an extension — the part after the last dot — that hints at what kind of file it is (hello.py for Python, notes.txt for plain text, photo.jpg for an image).
The address of a file is called its path. There are two kinds:
- An absolute path starts at the top of the filesystem and lists every folder down to the file. On macOS or Linux it might look like
/Users/ada/projects/study-log/main.py. On Windows it might look likeC:\Users\Ada\projects\study-log\main.py. - A relative path starts from wherever you currently are. If you are already inside
study-log, the same file is justmain.py. If you are one folder up, it isstudy-log/main.py.
The same file has both kinds of address. Relative paths are shorter and more common in code; absolute paths are unambiguous but tied to one specific machine.
Relative paths
0 / 5 points
The terminal is in a project folder that contains notes/today.txt. Which path is relative to the current working directory?
The Three Pieces
Working with Python locally involves three tools that play different roles:
- The Python interpreter — the program that actually runs your code. When you type
python main.py, this is the program that readsmain.pyand executes the instructions in it. - A code editor — a program for writing and editing
.pyfiles. You could use any text editor, but a real code editor gives you syntax highlighting, helpful warnings, and integration with the rest of the toolchain. - A terminal — a window where you type commands. This is how you tell the interpreter to run your code, and it is how you navigate around the filesystem from inside your project.
These are three separate roles. The editor is for writing; the terminal is for running; the interpreter is what actually runs.
The convenient thing about PyCharm is that it brings all three together in one program. PyCharm is an integrated development environment (IDE): it is a code editor with a terminal built in, and it knows how to find and manage a Python interpreter for you. So instead of installing and wiring up three separate things, you install one program — and, as you will see, it can even fetch Python for you if you do not already have it.
Installing PyCharm
Download PyCharm from jetbrains.com/pycharm. There is a free edition and a paid Professional edition; the free edition is all you need for this course. On the download page, pick the free option for your operating system.
- Windows: run the downloaded
.exeinstaller and accept the defaults. When it offers to create a desktop shortcut, that is fine to tick. - macOS: open the downloaded
.dmg, then drag the PyCharm icon into your Applications folder. Choose the file that matches your Mac — Apple Silicon (M-series) or Intel — if the page asks. - Linux: the simplest route is your distribution’s software centre (search for “PyCharm”), or install it from a terminal with
sudo snap install pycharm-community --classic. Alternatively, download the.tar.gzfrom the site and extract it.
Once it is installed, open PyCharm. The first time, it may ask a few setup questions (theme, and so on) — the defaults are fine. You will land on a Welcome screen with a button to create a new project.
PyCharm comes in a free edition and a paid Professional edition. The free edition has everything you need to write and run Python in this course. The Professional edition adds tools for web frameworks, databases, and remote development — useful later in a career, but not needed here. If the download page offers the free version under a slightly different name or as “free for non-commercial use,” that is the one to take. Download pages change; just choose the option that costs nothing.
Setting Up Python
PyCharm is the editor and the terminal, but it still needs a Python interpreter to actually run your code. The good news is that PyCharm can set this up while you create your first project, and — on Windows and macOS — it can download Python for you if you do not already have it.
From the Welcome screen, click New Project. In the dialog that appears:
- Choose a location — the folder where your project files will live. Set aside a folder for the course; PyCharm will create it if it does not exist.
- Look for the interpreter settings (sometimes labelled Python interpreter or Environment). Leave the default, which creates a small, self-contained environment just for this project. You do not need to understand the details yet — it simply keeps this project’s Python separate from the rest of your system.
- In the interpreter or base interpreter dropdown, PyCharm shows any Python it already found on your computer. If the list is empty, look for a Download Python (or Add Interpreter → Download) option and let PyCharm install one. Choose version 3.10 or newer.
- Click Create.
PyCharm now opens your project, with Python ready to use.
Older versions of PyCharm do not offer to download Python. If you do not see that option, install Python yourself first: go to python.org/downloads, download version 3.10 or newer for your operating system, and run the installer.
On Windows, the installer has a checkbox labelled something like “Add python.exe to PATH” at the bottom of the first screen. Tick this box. Then return to PyCharm’s interpreter dropdown — it will now find the Python you installed.
The Terminal: Navigating and Running
PyCharm has a terminal built in. Open it from the menu View → Tool Windows → Terminal, or click the Terminal tab along the bottom edge of the window. It opens at the bottom of the editor, already positioned in your project folder.
A terminal is a window where you type commands instead of clicking. You will use it for two things: navigating around the filesystem, and running your Python programs.
When the terminal opens, it is always somewhere in the filesystem — in some folder. That folder is called the working directory. The prompt usually shows it. Two kinds of command let you move around and look:
cd folder-namechanges the working directory intofolder-name.cd ..goes up one folder.ls(macOS, Linux) ordir(Windows) lists what is in the current folder.
For example, to step into a folder called study-log and see what is inside it:
cd study-loglsThe first command moves into it; the second lists its contents. Because PyCharm’s terminal starts in your project folder, you usually will not need the cd at all — you are already where you want to be.
To confirm that Python is reachable from this terminal, type:
python --versionYou should see something like Python 3.12.4. PyCharm’s terminal automatically uses the interpreter it set up for the project, so this should just work.
On macOS and Linux, the command is sometimes python3 rather than python — so python3 --version would work where python --version does not. On Windows, some setups expose Python as py. All of these are correct; the rest of the course writes python, but read it as python3 or py if that is the command that works for you.
Your First Local Program
Time to make all of this concrete. In your project:
- Create a new file called
hello.py. Right-click your project folder in the left-hand panel and choose New → Python File, then typehello. - Type the following into it and save (PyCharm saves automatically, but
Ctrl+S/Cmd+Snever hurts):
print("Hello from my own computer!")name = input("What is your name? ")print(f"Nice to meet you, {name}.")- Open the integrated terminal (View → Tool Windows → Terminal) and run:
python hello.pyYou should see the first message, then a prompt for your name, then the greeting. Congratulations — you have just run a Python program on your own machine, with no sandbox involved.
PyCharm also has a green Run button (the triangle near the top right, or right-click the file and choose Run). It does the same thing with one click. The course will keep using the terminal, though, because the terminal makes the working directory visible and predictable — and that turns out to matter a great deal once your programs start reading files.
If something went wrong:
- “command not found” or “is not recognized”: the terminal cannot find Python. Make sure you are using PyCharm’s built-in terminal (not a separate window), since that one knows about your project’s interpreter. Failing that, try
python3 hello.py(macOS, Linux) orpy hello.py(Windows). - “No such file or directory: ‘hello.py’”: the terminal is not in the right folder. Use
ls(ordir) to see what is in the current folder, andcdto move to the folder that containshello.py.
The second case is worth dwelling on, because it is the most common confusion when you start working with files.
The Working Directory
The terminal is always somewhere. When you type python hello.py, Python looks for hello.py relative to wherever the terminal currently is — not where the file actually lives, not where Python is installed, not where PyCharm is. If the terminal is in the wrong folder, Python will not find the file.
This is the same idea you will need in every chapter from now on. When you write code that says open("sessions.csv"), Python opens a file called sessions.csv in the working directory — the same place the terminal is currently sitting. Not the folder where your .py file lives. Not your home folder. The working directory.
For now, the recommended habit is simple:
- Put your project files in one folder.
- Open that folder as a project in PyCharm.
- Use the integrated terminal, which starts in that folder.
- Keep your data files (
.csv,.txt) in the same folder as your.pyfiles, at least until you have a reason to separate them.
If you stick to this layout, paths will mostly behave the way you expect. The complications come up in Defensive Programming with Files and External Data.
Diagnose a working directory problem
0 / 10 points
A learner has a PyCharm project with this structure:
course-work/ week4/ hello.pyIn PyCharm’s terminal, they type:
python hello.pyPython responds:
can't open file 'hello.py': No such file or directoryExplain the most likely cause and describe two ways the learner could fix it. In 3-6 sentences, use the terms working directory and relative path correctly.
Sandbox vs Local From Here On
You do not need to abandon the sandbox. It is still useful for quick experiments — testing a small bit of syntax, checking what a string method does, trying something out before deciding how to fit it into your project.
But the project lives locally from now on. The reason is simple: the sandbox cannot keep a file between runs. The whole point of this part is that your data survives between runs, and that requires real files on a real disk.
A few extra notes for Windows:
- If
pythondoes not work butpydoes, usepyfor the rest of the part. Thepylauncher is a Windows-specific way to run Python and is equivalent for our purposes. Inside PyCharm’s terminal,pythonwill usually work regardless. - Path separators on Windows are usually backslashes (
C:\Users\Ada\...) rather than forward slashes (/Users/ada/...). Python is generally tolerant of both, and you will see how to write paths that work on every operating system in Defensive Programming with Files and External Data. - If you find the Windows terminal workflow awkward, Windows Subsystem for Linux (WSL) is an option some learners prefer. It gives you a Linux environment inside Windows, and PyCharm can use it. The course does not require it, and the regular Windows tools work fine. WSL is just one of several valid setups.
Check Your Understanding
- What is the difference between an absolute path and a relative path?
- What do the three pieces — interpreter, editor, terminal — each do, and how does PyCharm relate to them?
- What does the working directory mean? Why does it matter when you run
python hello.py? - You typed
python hello.pyand got “No such file or directory: ‘hello.py’”. What is the most likely cause, and how would you fix it? - Why does PyCharm need a Python interpreter even though it is the program you write and run your code in?