This post will teach you about computers and show you how to set up a programming language called Python.
Operating Systems
A computer is characterized by its operator system, or OS for short. The most common operating systems are Windows, Linux/UNIX, and macOS. This guide will focus on Windows and macOS. If you have a macOS computer, for example, you can skip the sections about Windows.
What is a terminal?
A terminal is an interface that allows you to type commands. The commands that you type depend on what you want the computer to do. Each operating system has its own terminal. When you open a terminal, a window appears. After writing commands in the terminal, press the ‘return’ key on your keyboard, so that the computer can process what you typed.
Caution: be careful what you type in the terminal, since the terminal can be used to alter how your computer functions. In particular, be very cautious about the command rm as this is for removing files—potentially important files. Only remove a file if you know what you are doing. You will not need to use the rm command in this guide. If you are not sure of what a certain command does, Google it.
Slight errors, such as accidental typos, are usually not a problem because the terminal should display an error message. This guide will teach you how to use your computer’s terminal in a safe way, since most of the commands in this guide are for installing software from reputable sources. With that, the next step is to open a terminal on your computer. Using a terminal for coding will make your life easier in the long run, because you will have a stronger understanding of how a computer functions.
How to open a terminal
Windows
The Command Prompt is a terminal. To open the Command Prompt, there are at least two options:
- Hold down the Shift key, right click, and open the application called Command Prompt
- In the search bar, type cmd, and click on the application called Command Prompt
There are other terminals that you can use, but the Command Prompt will work for the purposes of this post.
macOS
To open the terminal on a macOS, select the search icon in the upper right corner of the screen, type terminal, and select the application.
What is an environment?
In the context of computer programming, an environment consists of a computer’s hardware and software on that device. Hardware and software changes from one device to another, since one user could install a software package that another user didn’t. A software package is basically reusable code. It is a good idea to keep track of what hardware and software is being used.
Conda
When coding in Python, conda can help you manage your computer’s environment. Conda is especially useful for managing software packages. In order to use conda, you can install Miniconda, which is located here:
https://docs.conda.io/en/latest/miniconda.html
After completing the installation of Miniconda, you will have access to conda, which is a very useful command that you can use in your computer’s terminal. The first thing you should do is install Python! To do this, type the following command into your terminal.
conda install python=3.11
The above line of code will install version 3.11 of python, which is the latest version available at the time of writing. The next thing you should do is create an environment. This can be done by typing the following in your computer’s terminal.
conda create –name environment_name python
Then you will need to activate the environment that you just created.
conda activate environment_name
You can choose any name for your environment. In this guide, the name of the environment is justenvironment_name. Now that an environment is created, you can list the software packages in that environment by typing
conda list –name environment_name
To install software called name_of_software in the environment called environment_name, use
conda install name_of_software
To verify that the software was installed in the environment called environment_name, use the same commands as before:
conda list –name environment_name
Installing a Jupyter Notebook
You will need a place to write and run Python code, and software called Jupyter Notebook makes this possible. To install Jupyter Notebook, type the following command in your computer’s terminal.
conda install notebook
Make a Simple Python Program
Now that those installations are complete, it is possible to write a python program. First, open a Jupyter Notebook by typing the following command into your computer’s terminal.
jupyter notebook
Next, select a folder, and click New Python 3 (ipykernal). This will create a Notebook where you can type Python code, to make a computer program. Don’t forget to rename your file from ‘Untitled’ to something more descriptive.
One of the simplest programs is one that prints the exclamation, “Hello, World!” as part of the program’s output. You can write this program by typing the following Python code into your Notebook.
print(“Hello, World!”)
Press the ‘Run’ button. The text “Hello, world!” should appear in the Notebook. If this is your first Python program, congratulations for making it to this point! Now you are set up to write and run Python code. In the next chapter, you will learn how to do more things with Python.
References
[1] Download python. Python.org. https://www.python.org/downloads/
[2] YouTube. (2019, January 29). How to install python on mac OS. YouTube. https://www.youtube.com/watch?v=TgA4ObrowRg
[3] GeeksforGeeks. (2022, July 1). How to install Pip in macos ?. GeeksforGeeks. https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
[4] YouTube. (2016, January 4). Windows command line tutorial – 1 – introduction to the command prompt. YouTube. https://www.youtube.com/watch?v=MBBWVgE0ewk
[5] YouTube. (2020, January 19). Linux terminal introduction. YouTube. https://www.youtube.com/watch?v=SkB-eRCzWIU
[6] Miniconda¶. Miniconda – conda documentation. https://docs.conda.io/en/latest/miniconda.html
[7] Project Jupyter. Installing Jupyter. https://jupyter.org/install
Leave a Reply