-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kristian Rother
committed
Jan 8, 2024
1 parent
fe1745e
commit a25bfd8
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |