Troubleshooting Python, VS Code, and GitHub
Find your problem below. If it is not here, or the fix does not work, see how to ask for help at the bottom of the page.
First checks
Most problems are one of these. Check them before anything else.
- Is the right folder open? The name at the top of VS Code’s Explorer panel should be your lab folder (for example week01_first_steps), not CSCI295.
- Is the right kernel selected? The upper right corner of the notebook should say .venv or the lab’s name, such as week01-first-steps. If it does not, click it, choose Python Environments…, and pick the lab’s own Python (path .venv/bin/python, or .venv\Scripts\python.exe on Windows).
- Did you just install something? Quit VS Code completely (on a Mac, command + Q) and open it again. A terminal only finds newly installed programs when it starts.
- What does the last line of the error say? Python error messages end with the name of the error and a short description. Start there.
Setup
uv: command not found or uv is not recognized
The terminal cannot find uv. Quit VS Code completely, open it again, and open a new terminal. If that does not help, run the uv installer from 000 again and read its last few lines of output, which say where it put uv.
git: command not found or git is not recognized
git is not installed, or the terminal cannot find it yet. Follow the git steps in 000, then quit and reopen VS Code.
File exists, already exists, or Project is already initialized
You ran a setup command in a lab folder that is already set up. Nothing is wrong, and nothing was changed. You set up each lab only once. See Coming back to your work.
The Mac asks to install developer tools
That is the installer for git. Click Install, agree to the license, and wait for it to finish (it can take a while).
Notebooks
There is no .venv to choose as the kernel
First look for the lab’s name in the list. Some versions of VS Code list the lab’s Python as, for example, week01-first-steps (3.14.x), with the path .venv/bin/python. If it is not there, the lab’s Python has not been set up yet, or VS Code has not noticed it.
- In a terminal in the lab’s folder, run
uv add ipykernel(for a lab you started yourself) oruv sync(for a lab from GitHub). - Open the Command Palette (command + shift + P on a Mac, Ctrl + Shift + P on Windows), run Developer: Reload Window, and try Select Kernel again.
VS Code marks Create Python Environment as Recommended
Do not choose it. Further down the list, pick the lab’s own Python (path .venv/bin/python, or .venv\Scripts\python.exe on Windows). This can happen if VS Code was set up earlier to use a different Python by default.
VS Code says running cells “requires the ipykernel package”
The notebook is using the wrong Python. Do not click Install. Click the kernel name in the upper right corner of the notebook and choose Python Environments… › .venv. If there is no .venv to choose, see the entry above.
ModuleNotFoundError: No module named 'pandas'
Python cannot find a package. Either the notebook is using the wrong kernel (check that it says .venv or the lab’s name), or the package is not part of the lab. For a lab from GitHub, run uv sync. For a lab you started yourself, add the package with uv add pandas (using the package’s name). Then click Restart in the notebook toolbar.
Do not install packages from inside a notebook (with !pip install, for example). That installs them in the wrong place, and the next person to run your notebook will not have them.
FileNotFoundError: [Errno 2] No such file or directory
Python could not find a file at the path you gave it.
- Paths in a notebook start from the folder the notebook is in, so the data folder is
../data/raw(up one folder, then down into data, then raw). Make sure your notebook is in the lab’s notebooks folder. (If you have used RStudio projects, this is different. There, paths start from the project’s folder, and here they start from the notebook’s folder.) - Check the file’s name, including capital letters and the ending (.csv, .txt). Click the file in the Explorer to be sure it is where you think.
SyntaxError or incomplete input
Python could not make sense of a line. The most common causes are a missing colon at the end of a line that starts with for, if, else, or def (the message says expected ':'), and a quotation mark or bracket that is opened but never closed. A bracket that is never closed gives '(' was never closed, or incomplete input when it is on the last line of the cell.
IndentationError
The lines inside a loop, an if, or a function must be indented by the same amount, usually four spaces, and the first line after the colon must be indented. Line the indents up and try again. VS Code indents for you after a colon. To stop indenting, press delete (backspace on Windows) at the start of the line.
NameError for something you know you defined
The kernel does not know about it yet. Maybe you have not run the cell that defines it since you opened the notebook (the kernel forgets everything when VS Code closes), or the name is spelled differently. Run the notebook’s cells from the top, or click Run All.
UnicodeDecodeError when you read a text file
Python assumed the wrong way of storing characters when it read the file. (The same mistake can also show up without an error, as garbled characters like ’ or é in your text.) Add encoding="utf-8" to read_text, as in read_text(encoding="utf-8"), and to write_text when you save text. Files from Project Gutenberg’s Plain Text UTF-8 versions are stored this way.
KeyError when you pick out a column
pandas has no column by that name. Run df.columns (with your DataFrame’s name) and compare. Look for spaces, capital letters, and spelling. If the names start with spaces, read the file again with skipinitialspace=True (see 030).
The truth value of a Series is ambiguous
You combined two conditions on a DataFrame with and or or, or without parentheses. In pandas, put each condition in parentheses and join them with & (and) or | (or), as in ice.loc[(ice["year"] >= 1981) & (ice["year"] <= 2010)]. If a filter keeps every row or none, check the parentheses too. Some missing parentheses give a wrong answer with no error.
It works when I run cells one at a time, but Run All fails
Run All stops at the first cell that makes an error. If that is an error you made on purpose, turn the line into a comment by putting # at the start of it.
Otherwise, the notebook depends on the order in which you happened to run cells, or on a cell you have since changed or deleted. Click Restart, then run the cells one at a time from the top, and find the first one that fails. Usually a variable is used before the cell that creates it, or a cell that creates it is gone.
The notebook is very slow, or nothing happens when I run a cell
Look at the upper right corner of the notebook. If the kernel is busy, a cell may be taking a long time (or waiting forever, for example in a loop that never ends). Click the Interrupt button (a square) to stop it, or Restart to start over.
GitHub
Make sure you configure your user.name and user.email in git
git needs to know who you are before you can commit. Run the git config commands in the GitHub guide.
You already use git under your own name for other work
The git config --global commands in the GitHub guide set your name and email address for every repository on your laptop. To use your GitHub username and private address only for repositories inside your CSCI295 folder, run these three commands in place of the first two in the GitHub guide (still run the third one, with pull.rebase), putting in your username and address:
git config --global 'includeIf.gitdir/i:~/CSCI295/.path' '~/.gitconfig-csci295'
git config --file "$HOME/.gitconfig-csci295" user.name "your-github-username"
git config --file "$HOME/.gitconfig-csci295" user.email "paste-the-address-here"To check, run git config user.email in a terminal inside one of your lab repositories. It should print the private address.
The invitation to the course’s organization has expired
GitHub invitations expire after seven days. Ask your instructor to send a new one.
GitHub asks you to turn on two-factor authentication
GitHub requires two-factor authentication for accounts that contribute code, so it may ask you to set it up. Follow GitHub’s steps. An authenticator app on your phone is the usual choice. Save the recovery codes it gives you somewhere safe, because they are the way back into your account if you lose your phone.
Cloning says Repository not found
Make sure you accepted the invitation to the course’s organization and then the assignment, and that you are signed in to GitHub (in the browser and in VS Code) with the same account whose username you sent us.
Pushing is rejected, or VS Code says your branch is behind
GitHub has commits that your laptop does not, for example a change made on GitHub’s website or on another computer. Click Sync Changes in the Source Control panel. It pulls the new commits and then pushes yours.
Sync Changes fails with a message that begins Git: From
GitHub and your laptop both have new commits, and git has not been told how to combine them. (The details, under Show Command Output, say “Need to specify how to reconcile divergent branches”.) Click Cancel, run this in a terminal, and then click Sync Changes again:
git config --global pull.rebase falseThis is one of the one-time setup commands in the GitHub guide.
VS Code says there is a merge conflict
You and someone else (or you, on two computers) changed the same part of a file. Stop and ask for help before you do anything else. Trying to fix it alone can make it worse.
Things not to do
- Do not delete the hidden .git folder, or delete your lab folder and clone it again, to fix a problem. Ask first. It can almost always be fixed.
- Do not make a course repository public.
- Do not edit files in data/raw.
Asking for help
A good help request gets you an answer much faster. Include:
- What you were trying to do, and which tutorial and step you were on.
- Exactly what you typed or ran. Copy and paste the code or command.
- The whole error message, copied and pasted as text. (A screenshot is great for a problem with VS Code’s windows or menus, but for an error message, text is better, because we can search it.)
- What you have already tried.
- Your operating system (Mac or Windows).
Bring your laptop to class or office hours, or email your instructor. Classmates are a good resource too, as long as you understand the fix well enough to explain it.