Solve your python errors using these steps

Yash Pawar
Artificialis
Published in
4 min readAug 19, 2021

--

While writing code you will probably run into errors, which is very common, and solving those errors needs you to do a few steps. This blog is beginners guide to solve those errors.

Let us have a look at what we will be covering:-

[
Reading the errors,
Trying to search for the error on the internet,
Using forums and communities
]

ok, so first we need some code, the things we are covering, looks like a python list to me, let me create a file and add this list to that file, this is how my file looks like

list of what we are covering in a python file

when I try to run this, I get an error, let’s have a look at it

$ python error.py

File "/home/yashp/code/error.py", line 2
Reading the errors,
^
SyntaxError: invalid syntax

let’s try to read what this error has to say. The last line which starts with the kind of error we have, here we have a SyntaxError which is followed by a message, which for us is invalid syntax meaning that we have some problem with our syntax, File "/home/yashp/code/error.py", line 2 means that in file error.py which is located in the folder /home/yashp/code contains the error on line number 2, we also see that it has printed line 2 for us, which is Reading the errors .

list of what we are covering in a python file without errors

After inspecting line 2 of model.py I found out that I did not add quotes around the sentences to make them strings, which is to be stored in the list, so now I have added quotes around them, and it works as expected without any errors.

Let’s now take an example of another error

This is the code for the next example, the first cell downloads the following code as a model.py file.

after you run that notebook’s second cell you will receive a NotImplementedError. the complete error is as follows:-

error after running the 2ⁿᵈ cell

let’s break this down, we see that the error is NotImplementedError, what does this mean? here is a link to an answer which defines NotImplementedError. and the error takes place at <ipython-input-2-8d64230b72fb> in <module>() which is nothing but the second cell of the notebook, and the error we have is on line 10 of the second cell, i.e. model(sample_data) .

search on stack overflow button on colab.

on google colab after running that cell, and getting that error we can see that it has a button that says Search StackOverflow, after clicking on that you will be redirected to google which has results that look like this:

result from google.com about the same error
results after clicking the ‘search stack overflow’ button

these results are from StackOverflow which is the first place you would like to visit for your error and also the main thing in the second point we are covering in this blog. instead of clicking that button, you can alternatively use search queries like “NotImplementedError StackOverflow” or “NotImplementedError PyTorch StackOverflow”, the 2nd result defines NotImplementedError for us, and the 4th result looks something similar to what we have if you check model.py you will see that this is similar but not what we want.

results after searching ‘NotImplementedError PyTorch’ on google

now we will try to search on the internet with the search query which is relevant to the error let’s try ‘NotImplementedError PyTorch’, we see that the 1ˢᵗ result is from StackOverflow, but the next ones are from PyTorch Forums, and the 2ⁿᵈ result says [SOLVED] so let’s have a look at that, after reading a few replies, we find that this reply by ptrblck says that it can be because of a typo or incorrect indentation, and we also find that in model.py forward is spelt incorrectly, we can just open this file and correct the spelling and run the cell again after restarting the kernel the error is no more there. (note: restarting the kernel is necessary, else python won’t load the changes else use the cached file, so we need to restart).

If with all these steps the error you are getting didn’t get solved you have Forums and communities to ask about your error, there are forums from the specific technologies themselves, like TensorFlow Forum, PyTorch Forum, fast.ai Forum and others. If it does not have a forum of itself you can ask on a more general forum/community like StackOverflow or others which you can find on discord/slack etc…

Summary:

  • The error Traceback gives us the information about where the error is and what the error is.
  • After identifying the error we should try to search about it on StackOverflow.
  • If we didn’t find anything on StackOverflow we should just try googling about the error. Try to look for answers on forums.
  • If the error is still not solved, ask on Forums (if possible official ones) and general communities.

Until next time, Have a great day ahead!.

Yash

--

--

Yash Pawar
Artificialis

Student | Learning AI/ML | Amazed with what Math can do | I love to Learn.