Mac OS Catalina ubuntu
I was interested in programming and bought a personal computer, but I don't know what to do from now on. For those who don't, here's what to do when you start programming on your Mac. In this article, I wrote a python program for the first time from the state I just bought a personal computer and it works The goal is to be able to do it.
First, build the environment. Building an environment means preparing to write a program on your personal computer.
The following is required to build a python environment.
I don't need it this time,
I think I'll need this later, so I'll put it together.
Let's put them in order.
Various installations differ depending on whether you are using Mac or ubuntu, so please see the installation method of the one you are using.
To write and run a program, you need a tool to write the program in the first place. This is called a text editor. VS Code is a kind of text editor and is recommended for beginners because it is easy to use.
Mac
Please download from here
When you click the link, a screen like the image will appear, so click the arrow part It will be downloaded.
Then, I think that it is in the download folder on the mac, so click it to open it.
The part indicated by the red arrow is the download folder.
This completes the vscode installation.
ubuntu
Please access here and click the part of the image below to install it.
Please return to the home screen when the download is complete.
Open the file
Select Downloads (or Downloads)
I think there is a file like a red circle so click on it
After that, another screen will appear, so enter the password and after a while, the installation will be completed.
Next, install python itself.
On Mac, python2 is included as standard, but the latest python is version 3 or higher, so I will include that.
You can download it by selecting the latest version of python from here and clicking it.
As before, it is in the download folder, so you can download it by clicking it to open it.
Next, I will insert the jupyter notebook. This is the same text editor as VS Code, but the specifications and usage are different from VS Code. This time I will just put it in, so I will omit the detailed explanation.
Mac
First, open the terminal. The terminal is like software that can directly instruct the personal computer, and it is in the utility of the application folder.
After opening the terminal, copy and paste the following (You can copy with command + c and paste with command + v while selecting what you want to copy)
pip install jupyter
The installation should complete after a while.
In the same way, if you type the following in the terminal and jupyter notebook starts up in the browser, it is successful.
jupyter notebook
ubuntu
First, open the terminal. A terminal is like software that can directly command a personal computer, and if you press Ctrl, Alt, and T keys at the same time, a black screen will appear. This is the terminal
Type the following command on that screen.
sudo apt install jupyter-notebook
Then you will be asked for the password, so enter it. The installation will be completed after a while. If you type the following in terminal and the screen appears, it is installed properly.
jupyter notebook
First, let's write a program. A program is like a collection of instructions to a computer, and the more complicated the instructions, the more instructions there are. A file is a collection of the procedures.
The general order for writing and executing a program is as follows.
Mac
First, create a file to write the program.
Type the following in the terminal
touch test.py
Then open vscode.
After opening vscode, press common + o to open the file you just created. There should be a file named test.py, click it and press Open at the bottom right.
Now that the file is open, let's write the program.
You don't have to understand the meaning of the program this time, so copy and paste the following into the file.
print("Hello World!")
Now that the program has been written, save it. (You can save it with command + s.)
Now let's run the program.
Type the following in the terminal:
python3 test.py
Then the result of the program you wrote earlier will be displayed.
ubuntu First, create a file to write the program.
Open terminal (press Ctrl, Alt and T at the same time and a black screen will appear.)
Type the following on that screen
touch test.py
You now have a file named "test.py".
ls
There is certainly a file named "test.py" when you type in!
And you can open the screen to edit the file of "test.py" with vscode by typing the following.
code test.py
Now that the file is open, let's write the program.
You don't have to understand the meaning of the program this time, so copy and paste the following into the file. (Since it says print, something seems to be displayed)
print("Hello World!")
Now that the program has been written, save it. You can save it with "Ctrl + S" (Ctrl + S).
Now let's run the program.
Go back to the terminal and type:
python3 test.py
Then the result of the program you wrote earlier will be displayed.
Recommended Posts