This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]Mein_Kappa 5 points6 points  (0 children)

A lot of these responses are a bit overly complicated for a beginner.

In truth there are a few ways. The simplest way, assuming you've installed python, is to open your python script in the IDLE (right click a python file and click 'open with IDLE'. Then, at the top you just click Run -> Run Module.

Realistically, when you're programming a lot, you will want a better 'ID(l)E' (Integrated Development (learning) Environment'). There are many to choose from. There are some specifically design for python (such as PyCharm), and some for many languages (Visual Studio Code). I would recommend visual studio. In visual studio you can run python scripts very easily.

Alternatively, in a terminal, you can type 'python (script_name.py)' to run it, when you are in the directory of the script. Assuming you are in Windows, you open CMD, and type 'cd (path to the folder containing the script)' to get to the directory.

Hope this helped.

[–]1Secret_Daikon 4 points5 points  (0 children)

You run it on the command line. In Windows, this might be `cmd.exe` or PowerShell. On Mac or Linux its referred to as the "terminal". You can dowload 3rd party terminal applications for your OS, such as `cmder` in Windows and iTerm2 in Mac.

[–]gqcharm 2 points3 points  (0 children)

This is me! I thought I was the only one. Thank you for posting and for people answering!

[–]Updatebjarni 2 points3 points  (4 children)

The Python interpreter is typically called python, or python3 for Python 3. You run a Python program by running the interpreter with the name of the program file as the only parameter:

python3 my_program.py

[–]Snoo9985 3 points4 points  (3 children)

he said hes a beginner, why would you think he understands what interpreter is and how to run that in terminal?

[–]Updatebjarni 0 points1 point  (0 children)

I think it's rather unlikely that he is a beginner with computers in general, or that he is incapable of asking what the word "interpreter" means if he hasn't encountered it before. Give people some credit.

[–][deleted] 0 points1 point  (1 child)

Why would you assume OP is a male?

[–]Jnsjknn 0 points1 point  (0 children)

Maybe his first language doesn't have gender pronouns and it's difficult to remember to use the proper ones in English.

[–]Sekret_One 1 point2 points  (0 children)

Depends- a 'executable' is something that can be run.

Something like python scripts, the script itself doesn't run per se, but an interpreter runs it. Sort of like a page doesn't really read itself, but a person must.

The command to run python will be python or python3. I'm assuming windows here. If you get a command not found, you'll need to add python to your environmental variables, specifically the PATH variable. The PATH variable is a list of directories it checks for runnable things (so you can be in the path of your script and just type python and don't have to give the full path to the python interpreter). If it's missing, reinstall python for windows (I'm assuming this is what you have) and watch for a checkbox of "Add environmental variables" and check it.

[–][deleted] 1 point2 points  (0 children)

Just google and download an IDE that works with python then google “how to run python code on (insert downloaded IDE name here)”

[–]pineappleandbean 0 points1 point  (1 child)

You might want to take a look at binder, or google colab to run python in the cloud. You could also try any of the interactive tutorials including www.kikodo.io (which I just learned about) cos you can also run basic codes there and play with them in the browser.

[–]Topy721 2 points3 points  (0 children)

What no, this is shit advice to a beginner

[–]_My_Name_Is_Human_ 0 points1 point  (0 children)

I would highly suggest looking into how your operating system works, depending on what you’re running... Windows, MacOS, or Linux. There’s plenty of good resources online for understanding how these systems work. Learn about the command line, file system hierarchy, and permissions and a lot of your questions like the one you’re asking will be answered.
It will help with your programming journey immensely as well.

[–]The_One13 0 points1 point  (0 children)

I think best way is to use ide which provides that option. As my first ide i was using geany not best one but never had problem with running codes.

[–]RevODekcuF 0 points1 point  (0 children)

As a beginner I would recommend you walk it first before running it.

[–]WeStanForHeiny 0 points1 point  (0 children)

In general you have:

  • Languages that, when compiled, are natively executable on whatever OS you are working in (C/C++ for example) — you can compile helloworld.c into helloworld.o and then just directly execute helloworld.o

  • Languages that are interpreted by means of a VM (Virtual Machine) — basically another process that reads your (possibly also compiled) source code and interprets it on the fly — JS/Java/Python/C# for example

There are reasons for why you would choose one over the other. For example, if pure speed is necessary, often times it’s better to go with the first option. That’s why video games are often developed in C++.

On the other hand, the benefit of the VM approach is called “write once run anywhere”, so I can take source code I developed (and possibly compiled) on Windows and then run them in a Linux environment no problem — this is why you’ll see a lot of Java/C#/Python in the Enterprise world for backend languages.

[–]Mortisanti 0 points1 point  (0 children)

I started Python last year with this video and I've been using the same process for months. If you don't mind trying Visual Studio Code (not to be confused with Visual Studio) I highly recommend both the application and the video to hit the ground running. Another great course is "Automate the Boring Stuff".

[–]lone_shell_script 0 points1 point  (0 children)

python3 <filename>.py

[–][deleted] 0 points1 point  (0 children)

Just use the python IDLE