Skip to content

Commit

Permalink
add recipe for exec from terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristian Rother committed Jan 8, 2024
1 parent fe1745e commit a25bfd8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Examples of common Python commands
:maxdepth: 1

reference/ipython_shell.rst
reference/run_from_terminal.rst
reference/basics.rst
reference/data_types.rst
reference/numbers.rst
Expand Down
55 changes: 55 additions & 0 deletions reference/run_from_terminal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

Running Code from a Terminal
============================

In this chapter, you find a recipe to run a Python program from a command line or terminal.
The recipe focuses on Windows users, because this is where the problem is most prevalent.

Step 1: Create a project folder
-------------------------------

Create a new folder for the project.
In this exammple, name it ``hello``.

Step 2: Create a Python file
----------------------------

Open your favorite code editor and create a new file ``hello.py``.
Write a single line into it:

.. code:: python3
print("hello world")
Store it in the new project folder ``hello``.


Step 3: Open a terminal
-----------------------

Start a new terminal session.

On Windows, search for **Anaconda Prompt** in the Start Menu.

In any case, you should see the text `(base)` at the beginning of the line with the prompt.
This means Anaconda is installed and the terminal is properly set up for it.

Step 4: Change directory
------------------------

Use the `cd <folder>` command to switch in the terminal to the new project directory.

On Windows, you can click into the address bar of the browser, copy the complete PATH to your project and paste it right after the `cd` command.

When you type `dir` or `ls`, you should see the contents of the folder.

Step 5: Run the program
-----------------------

In the same terminal, type:

::

python hello.py

And you should se the message `hello world` appear.

0 comments on commit a25bfd8

Please sign in to comment.