# Syntax Error in Python 3.10 when running on Terminal

**URL:** <https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462>\
**Category:** Python Help\
**Tags:** help\
**Created:** [March 19, 2022, 5:21am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462 "2022-03-19T05:21:16Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![PythonGuy](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@PythonGuy](https://discuss.python.org/u/PythonGuy)\
**Post date:** [March 19, 2022, 5:21am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/1 "2022-03-19T05:21:16Z")

</div>

Hey guys,  
I’m new to Python & I tried to run my 1st Python script (“Hello World”) on the terminal using Python 3.10.  
After access to the location of the py file, I tried to run it using:  
“Python .py” - but I got the following SyntaxError:  
“Leading zeros in decimal integer literals are not permitted; use an 0o for octal integers”.

Appreciating your assistace.

Thanks

---

<div class="post-metadata">

**Author:** ![gunungpw](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gunungpw/32/5832_2.png) [@gunungpw](https://discuss.python.org/u/gunungpw)\
**Post date:** [March 19, 2022, 5:45am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/2 "2022-03-19T05:45:42Z")

</div>

Hello, @PythonGuy you need to input the name of the python file (`.py`) to terminal.

- Make `helloworld.py` file with this code below:

```auto
print("Hello World")

```

- Go to the path/location of the file:

```auto
cd C:\path\to\file # Windows
cd ~/path/to/file # Linux

```

- Execute the file with this command:

```auto
python helloworld.py

```

- Your code will output:

```auto
'Hello World'

```

You can learn more from official tutorial:  
[https://docs.python.org/3/tutorial/index.html](https://docs.python.org/3/tutorial/index.html)  
or beginner free book here:  
[https://automatetheboringstuff.com/](https://automatetheboringstuff.com/)

---

<div class="post-metadata">

**Author:** ![PythonGuy](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@PythonGuy](https://discuss.python.org/u/PythonGuy)\
**Post date:** [March 19, 2022, 5:56am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/3 "2022-03-19T05:56:06Z")

</div>

Thanks but this is what I did exactly and got the syntax error previously mentioned:  
C:\Python310\Exfiles\>Python helloworld.py

---

<div class="post-metadata">

**Author:** ![gunungpw](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gunungpw/32/5832_2.png) [@gunungpw](https://discuss.python.org/u/gunungpw)\
**Post date:** [March 19, 2022, 5:57am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/4 "2022-03-19T05:57:38Z")

</div>

> [@PythonGuy](#):
>
> C:\Python310\Exfiles\>Python helloworld.py

use lowercase `python helloworld.py`

---

<div class="post-metadata">

**Author:** ![PythonGuy](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@PythonGuy](https://discuss.python.org/u/PythonGuy)\
**Post date:** [March 19, 2022, 5:59am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/5 "2022-03-19T05:59:40Z")

</div>

I did but with the same error

---

<div class="post-metadata">

**Author:** ![gunungpw](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gunungpw/32/5832_2.png) [@gunungpw](https://discuss.python.org/u/gunungpw)\
**Post date:** [March 19, 2022, 6:02am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/6 "2022-03-19T06:02:28Z")

</div>

can you show the code of `helloworld.py`?

and use the `<\>` toolbar in the editor to highlight your code like this:

````auto
```
type or copy paste your code here
```

````

---

<div class="post-metadata">

**Author:** ![soil](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/soil/32/6530_2.png) [@soil](https://discuss.python.org/u/soil)\
**Post date:** [March 19, 2022, 6:38am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/7 "2022-03-19T06:38:21Z")

</div>

I think, just writing `helloworld.py` will execute the file.(You must be inside the dir -where your file exists- in terminal, as @gunungpw has already mentioned about.)

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [March 19, 2022, 7:54am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/8 "2022-03-19T07:54:20Z")

</div>

Hi Gunung, thanks for trying to help, but you have given three answers that don’t have anything to do with the poster’s problem. He is not having trouble getting Python to look at the script, he is getting a SyntaxError, which means that Python has looked at the script and found a syntax error (invalid code) in the file.

PythonGuy, look at the SyntaxError you get:

“Leading zeros in decimal integer literals are not permitted; use an 0o for octal integers”.

The error message will show you the line that is invalid. Somewhere in that line, you have a number written like this:

```
0123

```

or something similar, with a leading 0 digit. You cannot use leading zero digits in Python ints. (They are allowed in numbers with a decimal point: `0.123` is allowed.)

To fix the error, remove the leading 0 digit: change 0123 to 123.

The reason for the error is that, in the past, Python copied the C programming language and used numbers with leading zeroes for base-8 “octal” numbers. So in old versions of Python, `0123` would be in octal.

The decimal number 83 is the same as:

- 53 in hexadecimal (base 16), which Python writes as 0x53
- 1010011 in binary (base 2), written as 0b1010011
- 123 in octal (base 8)

In old versions of Python, we used `0123` to mean octal, giving the decimal value 83. But that was confusing: too many people used a leading zero and then got the wrong result.

So Python changed the rules. To write an octal number today, we write it as `0o123` not `0123`, and to avoid accidental mistakes the leading zero is prohibited.

So to fix your SyntaxError:

1. Read the error, and see which line of code it refers to.

2. Find the number with a leading zero on that line of code.

3. If you intended it to be octal, then change it to use `0o...`

4. If the zero was just a placeholder, then just remove it.

---

<div class="post-metadata">

**Author:** ![gunungpw](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gunungpw/32/5832_2.png) [@gunungpw](https://discuss.python.org/u/gunungpw)\
**Post date:** [March 19, 2022, 9:10am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/9 "2022-03-19T09:10:50Z")

</div>

@steven.daprano thanks 👍, I just guessed OP problem, and because of that I ask the code of the script. Thank you for actively answered beginner question in forum, i still learning English and programing in general. Hope you have a nice day 🙂

---

<div class="post-metadata">

**Author:** ![Quercus](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/quercus/32/31483_2.png) [@Quercus](https://discuss.python.org/u/Quercus)\
**Post date:** [March 19, 2022, 2:15pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/10 "2022-03-19T14:15:53Z")

</div>

Hello, @PythonGuy, and welcome to Python Foundation Discourse!

If you had posted your code here, we could offer more effective help. If you do post code, please make sure it is formatted correctly.

Some examples of types of numbers that can be used in Python programs are integers and real numbers. Examples of integers, correctly expressed for Python, include:

- `42`
- `144`
- `-14`

Examples of real numbers include:

- `3.17`
- `-77.4`

The following would not be accepted as integers by Python, because they each have a leading `0`:

- `077`
- `-077`

The above would each raise a `SyntaxError`.

When writing a program, it is important to consider what types of data you are using. A count of some kind of object, such as a number of slices of pizza, would be appropriately expressed as an integer, such as `3`. However, if you were to specify the name of something, such as a programming language, you would most likely use a string, of which the following are examples:

- `"Python"`
- `'Ruby'`

Note that the strings are contained in either double or single quotes.

Some entities that are commonly referred to as numbers are not actually numbers. At a bank or on an electronic device, you may be asked for a pin number. Most likely, that pin number should be thought of as a string, rather than as a number, even though it might consist entirely of digits. In many situations, valid pin numbers could begin with a `0`. Therefore, if your Python program contains a pin number, you should very likely enclose it in quotes. The following would be valid:

```auto
pin_number = "0276"

```

However, this would raise a `SyntaxError`:

```auto
pin_number = 0276

```

We hope you enjoy the discussions here. You may be interested in reading the following pages, which offer helpful information about this forum:

- [Python Discourse Quick Start](https://discuss.python.org/t/python-discourse-quick-start/116)
- [About Discussions on Python.org](https://discuss.python.org/about)

---

<div class="post-metadata">

**Author:** ![PythonGuy](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@PythonGuy](https://discuss.python.org/u/PythonGuy)\
**Post date:** [March 19, 2022, 6:27pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/11 "2022-03-19T18:27:13Z")

</div>

> [@gunungpw](#):
>
> `code `

print (“hello World”)  
hello World

---

<div class="post-metadata">

**Author:** ![PythonGuy](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@PythonGuy](https://discuss.python.org/u/PythonGuy)\
**Post date:** [March 19, 2022, 6:44pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/12 "2022-03-19T18:44:30Z")

</div>

Thank you Steven for this elaborated feedback.  
My starting script is just 1 line reading:  
Print (“Hello World”).

It runs properly on the IDLE where created but with that syntax error on the terminal.

---

<div class="post-metadata">

**Author:** ![Quercus](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/quercus/32/31483_2.png) [@Quercus](https://discuss.python.org/u/Quercus)\
**Post date:** [March 19, 2022, 6:51pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/13 "2022-03-19T18:51:37Z")

</div>

> [@PythonGuy](#):
>
> Print (“Hello World”)

That code would not execute, as is, because `print` needs to begin with a lowercase `p`. When posting code, it is necessary to literally copy and paste it, then to format it.

_EDIT (March 19, 2022):_

It also must be mentioned that the following program would raise a `SyntaxError`, but not one concerning a leading `0`:

```auto
Print (“Hello World”)

```

However, perhaps you had another script named “.py”.

> [@PythonGuy](#):
>
> I tried to run it using:  
> “Python .py”

On my MacBook Air, I wrote the following program, and renamed it as above:

```auto
# The name is Bond, James Bond.
print(007)

```

Then, running it from the terminal with the command reported above, part of the result was:

```
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

```

So, it is possible that you mistakenly activated a script other than the intended one, and that raised the reported error.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [March 20, 2022, 12:08am UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/14 "2022-03-20T00:08:00Z")

</div>

Hi Anthony,

There is no possible way to get the SyntaxError you reported from a file with just one line `print("Hello World")`.

Possibly Gunung was correct, and you are running the wrong script.

We cannot help you now unless you copy and paste the **full** command you give on the terminal and the error you receive.

Please tell us:

- What operating system you are using.

- What command you used on the terminal.

- What the result was.

Please don’t summarise it, or re-type from memory. We need to see the **exact** unedited command and result, otherwise we cannot help you.

---

<div class="post-metadata">

**Author:** ![PythonGuy](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@PythonGuy](https://discuss.python.org/u/PythonGuy)\
**Post date:** [March 20, 2022, 6:34pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/15 "2022-03-20T18:34:24Z")

</div>

Hello Steven;

1. OS: Windows 10 Pro (vers. 21H1)/ 64 bit/ x64-based processor.
2. Python 3.10.
3. Terminal: C:\Python310\Exfiles\python helloworld.py
4. Result:  
File “c:\Python310\Exfiles\helloworld.py”, line 1  
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32  
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers.

To note here that the exact same result mentioned above is popping up every time I tried to run each of the 5 one-line scripts I created for testing with 1 single command print(’’).

“c:\Python310\Exfiles\>dir” lists for me all the py files created & saved therein and I tried to run them one after the other as described earlier with the exact same result.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [March 20, 2022, 10:02pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/17 "2022-03-20T22:02:05Z")

</div>

The first line of your helloworld.py file says:

```
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32

```

Remove it. It is not valid Python code, it is a line of junk that does not belong in a Python script, and the interpreter has got confused by the “07”. By my count, there are at least 15 syntax errors in that junk line, and the interpreter had to pick one to report, it just happened to be the “07” one.

The lessons here:

(1) It helps to look at the **full** error message Python gives you.

Python will show you the line of the script it thinks is wrong. That helps you to see which line of your script usually contains the error, or at worst, maybe the previous line.

(2) Always double and triple check the file you are running contains what you expect. You told us that the file contained one line, `print("Hello World")` but that was not correct, there was an extra line of junk at the start of the file.

If you had given us accurate information from the beginning, and shown us the full contents of the file:

```
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
print("Hello World")

```

or the full traceback, we could have answered your question **instantly** , instead of taking 15 posts and well over a day to solve it.

This is part of learning to be a programmer! We know how to solve these problems because we know how to use the information the interpreter gives us, and because we’ve all made these same errors (or very similar ones) ourselves.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [March 20, 2022, 10:20pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/18 "2022-03-20T22:20:05Z")

</div>

Ahaha! And a further mystery is solved.

I am sure that you **did not** type the line “Python 3.10.3 (tags/v3.10.3:a342a49 blah blah blah…” into your helloworld.py script.

What I believe happened is that you used IDLE. You opened IDLE, and it started by giving you the interpreter window.

The interpreter window starts off by running the interpreter, which prints a welcome banner showing the version of Python, then a `>>>` prompt.

You then typed `print("Hello World")` at the prompt. All good so far.

Now the mistake, but an understandable one.

You used the IDLE “Save” or “Save As” command to save that to a file. But unfortunately, IDLE doesn’t just save your code, it also saves the banner (“Python 3.10.3 …”) to the file.

Which is, I think, a bug in IDLE:

[https://bugs.python.org/issue45297](https://bugs.python.org/issue45297)

Until this is fixed in IDLE, which may not happen for a while, the best way to use IDLE to save your code is to always use the Open command and check the script, removing any of the unwanted junk lines added to the file.

---

<div class="post-metadata">

**Author:** ![PythonGuy](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@PythonGuy](https://discuss.python.org/u/PythonGuy)\
**Post date:** [March 21, 2022, 1:26pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/19 "2022-03-21T13:26:40Z")

</div>

Thanks.  
sorry for wasting your time.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [March 21, 2022, 10:25pm UTC](https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462/20 "2022-03-21T22:25:41Z")

</div>

Its all part of the learning process!

Just remember, the Python interpreter goes to great lengths to give you as much information as it can about what went wrong. (Well, at least sometimes.) As you learn how to read that information and what it means, you will learn to solve bugs on your own.
