Fix: SyntaxError: ( was never closed [Python]

If you are very new to Python Programming and trying to run your .py file in the command line (or terminal) and you see the error "SyntaxError: '(' was never closed", well then you have look at the error text and grab more details from it.

How to know which line has the issue?

When you run your Python code and it generates an error you can a traceback printed out in the console which contains the details of the error.

Let's understand this with a simple example.

print("Hello World"

When I run this file in the terminal I get the below traceback

1.  % python3 
2.   File "/Users/c2ctech/Desktop/", line 1
3.    print("Hello, World!"
4.         ^
5. SyntaxError: '(' was never closed

There are a few important things to note here, at line number 2, you will see which file had an error and at what line. Note, we are getting this error on line 1.

Line number 3 highlights exactly at what statement the error is and line 5 tells us that it is a SyntaxError.

So you read the error as "There is a SyntaxError on line 1 of my file"

How to fix this error

The fix is self-explanatory, but one could be very new to programming, so let me elaborate, every programming language has a syntax, a structure that you should follow, if it is not followed correctly, you get errors when you run your code.

The print function in Python needs to be enclosed within parenthesis, If you miss the closing braces, you will get this error we are dealing with here.

The fix is simple, make sure to close the print function with a closing parenthesis.

print("Hello World")
SyntaxError- ( was never closed - Python

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap