Python Forum
to call via console a python-programm - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: to call via console a python-programm (/thread-31073.html)



to call via console a python-programm - Liki - Nov-21-2020

Hello,

I'm trying to call an in Python frish-written programm zeit_01 via console.
It didn't run. What I did false?:

[Image: Wp6wDxY.jpg]

one step more:

[Image: lMXUVA3.jpg]

How do it right?


RE: to call via console a python-programm - bowlofred - Nov-21-2020

Your PATH has to have a directory that contains the installed python executable like python3.exe or python.exe, not your project or .py files.

It looks like you've changed PATH to something else and now it can no longer find python.

Try opening a new cmd window and run python -V. It should show a version number and then you can try to run your program.


RE: to call via console a python-programm - Liki - Nov-21-2020

Thank you.

(Nov-21-2020, 01:27 AM)bowlofred Wrote: Try opening a new cmd window and run python -V. It should show a version number and then you can try to run your program.

[Image: Y0GywRL.jpg]

and?
I would like to open the existing programm zeit_01.py I do it like described in the book (s. screenshot before), but it doesn't run so... Wall

here is hte PARTH and file python.exe (or pytonw.exe? I'm using also PythonWin):

[Image: DOdIYgY.jpg]


RE: to call via console a python-programm - Liki - Nov-21-2020

I think so I've called the python3.9.0 via console:

[Image: VxXx98s.jpg]

I would like to ask how could I call the file zeit_01.py via console?


RE: to call via console a python-programm - bowlofred - Nov-21-2020

Go into the directory where the file is and run C:> python zeit_01.py. Python will be found because it is in your PATH; zeit_01.py will be found because it is in your current directory.


RE: to call via console a python-programm - Liki - Nov-21-2020

The file zeit_01 is here:

[Image: 3MtzS3F.jpg]

and I did so:

[Image: e7QJoXK.jpg]

but...

In the book are followed additional options offered:

C:\python\...project...> /python3/python zeit_01.py

or

C:\python\...project...> py -3.9 zeit_01.py


RE: to call via console a python-programm - Liki - Nov-21-2020

[Image: irdFuTC.jpg]


RE: to call via console a python-programm - bowlofred - Nov-21-2020

The default installer will also create a py.exe in your path. You can use that instead if you prefer.

The >>> string is the prompt from the interactive python interpreter. You can type python commands, but that's not how you run python scripts. Run them from the C:> prompt. Are you typing the "C:\Python39...." stuff? That should just be a prompt, not the part you type.

C:\> py zeit_01.py
or
C:\> python zeit_01.py
Note no ">>>" in the prompt.


RE: to call via console a python-programm - Liki - Nov-21-2020

Thank you. So was it solved:

[Image: vz65ow3.jpg]


RE: to call via console a python-programm - bowlofred - Nov-22-2020

If python is in your path, you shouldn't need the full name to python, just "python".

If you are in the directory with your program, you don't need the full path to your script.

Both are fine, but I would normally be trying to shorten the amount of typing I have to do.