# Invoking the Interpreter

**URL:** <https://discuss.python.org/t/invoking-the-interpreter/37069>\
**Category:** Python Help\
**Tags:** documentation, help\
**Created:** [October 24, 2023, 8:23pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069 "2023-10-24T20:23:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Violet](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/violet/32/15636_2.png) [@Violet](https://discuss.python.org/u/Violet)\
**Post date:** [October 24, 2023, 8:23pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/1 "2023-10-24T20:23:16Z")

</div>

Hello, I have absolutely no experience with coding but decided to start studying all the available information in Python Docs. I just started reading _The Python Tutorial_ and I am already in need of help understanding! In Section 2.1 Invoking the Interpreter it states:

![unnamed](https://us1.discourse-cdn.com/flex002/uploads/python1/original/2X/7/769ea32529745e9108d7dfb07f0b3caf2eec1ee0.png)

I tried typing that into my Windows Command Prompt, but it says: `name 'command' is not identified`

Then I tried quoting command a few different ways with the following error results:  
**python -c “command” [arg] …**  
`name 'command' not identified`  
**python “-c command” [arg] …**  
`command unexpected indent`  
**“python -c command [arg] …”**  
`python is not recognized as an internal or external command, operable program, or batch file`

I know there are other ways to launch the interpreter but I want to know/learn everything and exactly how it works or why it wont work for me. I tried the other options the tutorial gave to launch the interpreter and had no issues.

I’m hoping someone could tell me how to use **python -c command [arg] …** exactly to launch the interpreter. I am using Windows and the Windows Command Prompt so I’m thinking maybe that code is for Unix users? Any replies with your ideas and/or solutions will be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![ketozhang](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@ketozhang](https://discuss.python.org/u/ketozhang)\
**Post date:** [October 24, 2023, 8:45pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/2 "2023-10-24T20:45:35Z")

</div>

Let’s start by ignoring the `[args]` (square bracket means optional). So it is instead `python -c command`.

Here `command` is not to be taken literally. It’s a placeholder of the command you want to write—a better word for command is code\[1\]. For example:

```sh
$ python -c "print('Hello, World!')"

```

* * *

1. It is a bit out of style, in my opinion.

---

<div class="post-metadata">

**Author:** ![merwok](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/merwok/32/29_2.png) [@merwok](https://discuss.python.org/u/merwok)\
**Post date:** [October 24, 2023, 8:48pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/3 "2023-10-24T20:48:16Z")

</div>

It is correct, you can pass command (code, as you pointed it) and argument(s) for that code.  
Try this: `python -c "import sys; print(sys.argv)" one "t w o" three`

---

<div class="post-metadata">

**Author:** ![Violet](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/violet/32/15636_2.png) [@Violet](https://discuss.python.org/u/Violet)\
**Post date:** [October 24, 2023, 9:35pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/4 "2023-10-24T21:35:09Z")

</div>

`python -c command`  
outputs an error stating name ‘command’ is not identified

`"python -c command"`  
outputs an error stating: python -c command is not recognized as an internal or external command, operable program, or batch file

`python "-c command"`  
outputs an error stating: command IndentationError: unexpected indent

---

<div class="post-metadata">

**Author:** ![Violet](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/violet/32/15636_2.png) [@Violet](https://discuss.python.org/u/Violet)\
**Post date:** [October 24, 2023, 9:38pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/5 "2023-10-24T21:38:18Z")

</div>

this code did not launch my Python interpreter but it do something:

![image](https://us1.discourse-cdn.com/flex002/uploads/python1/original/2X/5/5e1e25d7f536eeb500b3f124f64c934cc728949b.png)

---

<div class="post-metadata">

**Author:** ![jamestwebber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamestwebber/32/12799_2.png) [@jamestwebber](https://discuss.python.org/u/jamestwebber)\
**Post date:** [October 24, 2023, 9:41pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/6 "2023-10-24T21:41:06Z")

</div>

If you just want to launch the interpreter and get an interactive prompt, you don’t need any arguments at all. Just `python`

---

<div class="post-metadata">

**Author:** ![Violet](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/violet/32/15636_2.png) [@Violet](https://discuss.python.org/u/Violet)\
**Post date:** [October 24, 2023, 9:45pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/7 "2023-10-24T21:45:30Z")

</div>

I understand that, its just going to bug me if I don’t figure it out, lol! The Python Tutorial says you can launch the interpreter with that argument so there must be a way and I will learn it!

---

<div class="post-metadata">

**Author:** ![ketozhang](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@ketozhang](https://discuss.python.org/u/ketozhang)\
**Post date:** [October 24, 2023, 9:50pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/8 "2023-10-24T21:50:47Z")

</div>

That code did launch an interpreter. However, what you were expecting is for the Python interpreter to be ran in interactive mode (aka Python REPL). See the [next section](https://docs.python.org/3/tutorial/interpreter.html#interactive-mode) in that tutorial.

---

<div class="post-metadata">

**Author:** ![Violet](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/violet/32/15636_2.png) [@Violet](https://discuss.python.org/u/Violet)\
**Post date:** [October 24, 2023, 9:54pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/9 "2023-10-24T21:54:18Z")

</div>

Oh, so the interpreter and interactive mode are different?

---

<div class="post-metadata">

**Author:** ![jamestwebber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamestwebber/32/12799_2.png) [@jamestwebber](https://discuss.python.org/u/jamestwebber)\
**Post date:** [October 24, 2023, 9:59pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/10 "2023-10-24T21:59:59Z")

</div>

`python` is the interpreter itself: it is a program that interprets the python language you feed to it, and executes the code. So “launching the interpreter” is just a way of saying “running the `python` executable”

---

<div class="post-metadata">

**Author:** ![merwok](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/merwok/32/29_2.png) [@merwok](https://discuss.python.org/u/merwok)\
**Post date:** [October 24, 2023, 10:25pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/11 "2023-10-24T22:25:08Z")

</div>

> [@Violet](#):
>
> `python -c command`  
> outputs an error stating name ‘command’ is not identified

What is the exact error message?

If it is `NameError: name 'command' is not defined`, it’s because the doc means that `command` is a placeholder, it represents actual real python code that you can type (like my example with an import and a print, with a semicolon to separate them because that’s easier than a newline).

General rule; to get help, always show the exact code and exact error message.

> [@](#):
>
> `"python -c command"`  
> outputs an error stating: python -c command is not recognized as an internal or external command, operable program, or batch file

Here the quotes make one big string out of all you typed, so you’re effectively asking your shell to find a program named “python SPACE -c SPACE command”, which does not exist. You have to call the `python` program, with additional arguments added after spaces. The Python tutorial says a little about that: [2. Using the Python Interpreter — Python 3.12.0 documentation](https://docs.python.org/3/tutorial/interpreter.html) – but not too much, as it’s not its responsibility to teach general shell usage.

> [@](#):
>
> `python "-c command"`  
> outputs an error stating: command IndentationError: unexpected indent

Here the quotes mean that the python program receives one argument, which is `-c SPACE command`.  
That’s not a valid form: the doc in your screenshot shows clearly that `-c` is one thing, then the command (python code, valid python statements), then arguments for that command, all separated with spaces.

---

<div class="post-metadata">

**Author:** ![djhenderson](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/djhenderson/32/1483_2.png) [@djhenderson](https://discuss.python.org/u/djhenderson)\
**Post date:** [October 25, 2023, 5:46am UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/12 "2023-10-25T05:46:24Z")

</div>

When you install Python on Windows, the installer has a checkbox to add the path to the Python folders to the PATH variable. You have two possibilities:

Python not in PATH: You must use the **py** command ( **C:\Windows\py.exe** ). In a command or terminal window, using the **py** command starts Python in interactive mode, and using **py _script.py_** will have Python run the _script.py_ program.

Python in PATH: You may use the **py** command as described above. You can also use the **python** command to enter interactive mode or the **python _script.py_** command to have Python run the _script.py_ program.

Linux and MacOS do not have a **py** command so they always uses the **python** or **python3** commands.

If you want to use **py -c “_code_”** or **python -c “_code_”** , on Windows, you must use the double quote characters around the entire _code_ string. Embedding double quote characters in the _code_ string is difficult, so it is better to try to use single quotes or triple single quotes between the double quotes instead.

On Linux or MacOS, you can use either the single or double quote character (depending on shell quoting requirements for _code_).

---

<div class="post-metadata">

**Author:** ![Violet](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/violet/32/15636_2.png) [@Violet](https://discuss.python.org/u/Violet)\
**Post date:** [November 6, 2023, 6:10pm UTC](https://discuss.python.org/t/invoking-the-interpreter/37069/13 "2023-11-06T18:10:41Z")

</div>

Okay so I haven’t stopped asking around and trying to figure out this ‘problem’. I have come to a conclusion about this issue and I couldn’t have done it without all the comments and messages received so thank you everyone! Here it is:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/python1/original/2X/b/babac226d6edeeb71dbd5585b74166f2e9c44b8b.png)

To my understanding, paragraph 1 states that when it’s connected to a TTY device, THATS when it is able to execute commands.  
The code I’ve been asking about is a command statement.

I then started researching TTY and found out that:

![image](https://us1.discourse-cdn.com/flex002/uploads/python1/original/2X/c/c60c27dc06eb99d274a0889404b845c6f7c3c560.png)

Which I have Windows 10 so I have been trying to make this code work for me and I dont even have a TTY!

Conclusion: The second way to launch the interpreter is a ‘hack’ for Unix users and user must have TTY device. Therefore, there is no way _(at the moment)_ for myself to successfully execute this command. Oh well, I’m glad I know now though!
