1. Introduction
In this course, Python
, version 3.7
or above is required. Here, the Ubuntu
operating system is used to test the codes. You may use any other operating system. There are various ways to install Python on your computer. In this course, we recommend using Anaconda
to install Python. Anaconda will automatically install most of the required libraries in this course.
To write and edit the Python programs you can use any plain text editor, such as gedit
, nano
, vi/vim
, notepad
, or any other. In this course, we recommend Visual Studio Code Editor
, but you can use any other editor of your choice.
To install Python in Ubuntu using the Anaconda and to install the Visual Studio Code Editor, follow the following steps.
1.1. Install Anaconda
1.1.1. Installing Anaconda on Linux
-
Download Anaconda for Linux x86 system from https://www.anaconda.com/download/#linux. It may take a few minutes to download. In this case,
Anaconda3-2022.10-Linux-x86_64.sh
was downloaded (~ 738 MB). In your case, you may have downloaded a later version, which is fine. -
Launch terminal using Ctrl+Alt+T
-
Navigate to the Downloads directory where the Anaconda download was saved. Use
cd Downloads
-
To check if
Anaconda3-2022.10-Linux-x86_64.sh
was successfully downloaded in the Downloads directory, usels
as shown in Figure 1.
-
Verify the installer integrity using SHA-256.
shasum -a 256 Anaconda3-2022.10-Linux-x86_64.sh
. ReplaceAnaconda3-2022.10-Linux-x86_64.sh
with your file pathshasum -a 256 /PATH/FILENAME
. This step is not mandatory but it is recommended. You should see an output such ase7ecbccbc197ebd7e1f211c59df2e37bc6959d081f2235d387e08c9026666acd
-
Install Anaconda by running
bash Anaconda3-2022.10-Linux-x86_64.sh
and follow the instructions. Press Enter to read every page of the agreement document or press Q to go to "Do you accept the license terms?". Typeyes
to agree and continue orno
to quit and stop the installation. Press Enter to confirm the installation directory and continue with the installation. -
To check if Anaconda has been installed successfully as shown in Figure 2, run
anaconda -V
oranaconda --version
. You should see a terminal output, such asanaconda Command line client (version 1.11.0)
.
1.1.2. Installing Anaconda on Windows
To easily follow the commands in this course on Windows, before installing Python using Anaconda, we recommend that you install Windows Subsystem for Linux (WSL):
-
Open Power Shell or Command Prompt as an administrator.
-
Type
wsl --install
and Enter -
Wait until the download is complete. If it freezes at a certain percentage and takes too long, the installation is most likely complete. Quit using CTRL+C.
-
Reboot the computer.
-
After you log in to Windows,
WSL
will ask forusername
andpassword
. These details do not have to be the same as that for Windows. -
You can now install Anaconda on this WSL terminal by following the above steps.
For details, refer to (Install WSL | Microsoft Learn, n.d.).
To install Python using Anaconda on other operating systems, refer to (Installation — Anaconda Documentation, n.d.). |
1.2. Install Visual Studio Code Editor (vscode)
Downloading and installing vscode is rather straightforward.
-
Download vscode from https://code.visualstudio.com/ and follow installation instructions.
-
For details refer to (Documentation for Visual Studio Code, n.d.).
-
Having installed the vscode, open the terminal Ctrl+Alt+T and type
code
and Enter. This will open the vscode and it will be ready to save your programs inDocuments
directory. If you want to open vscode in another directory, say,Documents/Python
, navigate to that directory usingcd Documents/Python
. Alternatively, you can go to the installed programs, find vscode, and click it to open. -
If vscode may ask you to install python extensions, please accept and install them.
To activate WSL on vscode on Windows, install WSL extension. Click the icon on bottom left corner and you may select WSL: New WSL Window using Distro or WSL: Reopen Folder in WSL. For details, refer to (Developing in the Windows Subsystem for Linux with Visual Studio Code, n.d.).
|
1.3. Test if Python Works
-
In vscode, go to
Make a new file and name ittest.py
. and write the following short program. -
An easy way to open the vscode and at the same time create the new file is as follows.
-
Open terminal Ctrl+Alt+T
-
Using one command, open vscode, navigate to documents directory, and create a new file:
code Documents/test.py
then Enter -
Type the following program and then save it Ctrl+S
-
1.3.1. Python Test Program
-
On the left side of vscode, right-click on the
. -
To run the python code type the following command in the terminal
python test.py
-
This should print the following. See Figure 3
|
Figure 3. Python unicode test program.
|
To clear the terminal, enter the following command clear
. Test the following program and run it the same way as above. You can just write the following program just below the above program.
1.3.2. Python Calendar Program
|
Figure 4. Python calendar on the terminal.
You can print the full year using |
1.4. Installing Libraries Using conda
Sometimes we may need a special library that will help us to easily write a program that would otherwise be more complicated to write. In this section, we shall install install python library using pip
and conda
, and test it using a python code.
-
To install
pip
viaconda
, open command terminal or use the same vscode terminal type this command:-
conda install pip
-
-
Install the following library.
-
conda install pywhatkit
this library can help us to change a given typed text into handwritten notes.
-
-
Using the same vscode terminal, enter the following command
code handwriting.py
to make and open a new python file called handwriting.py -
Type the following program and run it by using
python handwriting.py
.
1.4.1. Python Typed-Text-to-Handwritten Program
|
Figure 5. Python typed text to a handwritten image.
|
1.5. Basic Linux Terminal Commands
If you are using Ubuntu
, open terminal Ctrl+Alt+T
If you are using wsl
and vscode
on Windows, go to vscode menu, click .
print the current working directory (
You should see an output such as this /home/sam |
list the contents of a folder/directory (
You should see an output list such as this anaconda3 bin Pictures Music Public opt Desktop Documents Downloads |
change the directory (
sam@siliconwit:~/Downloads$ The above command should take you to the
Anaconda3-2022.10-Linux-x86_64.sh ABDTR894278.bibtex |
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Comments