KEMBAR78
Intro to Programming Week 2_Python Installation.pptx
INTRODUCTION TO PROGRAMMING
IKSAN BUKHORI, M.PHIL.
PYTHON INSTALLATION
TWO WAYS TO INSTALL
 You can either choose to install Python directly, or through a package manager. One of the most popular
one is called Anaconda
 Installing Python directly is easier, and only installs additional very lightweight IDE called IDLE. You can
write python program by either
1. Write and run it through IDLE
2. Write and run the code directly from command prompt
3. Installing other IDEs and write/run the program from there
4. Write the python code in a notepad or notepad++ and run it through command prompt
 On the other hand, direct python installation only installs a package manager called pip, and you will
only have access to packages in Python language
TWO WAYS TO INSTALL
 Installing Anaconda also installs python (if python has not been installed yet).
 Installing Python directly is a little bit more complicated, and it installs a comparatively more heavy
Anaconda navigator. You can write and run python program by
1. Write and run it through IDEs which can be installed from Anaconda Navigator
2. Write and run the code directly from anaconda prompt
3. Write the python code in a notepad or notepad++ and run it through anaconda prompt
 On the other hand, python installation through Anaconda installs a package manager called Conda, and
you with this you can have access to packages written not only in Python but other languages too.
DIRECT PYTHON INSTALLATION
PYTHON INSTALLATION
 Go to https://www.python.org/downloads/windows/
 Download the latest release of Python
 Run the installer, and make sure to add python to PATH
WORKING WITH COMMAND PROMPT
CODING IN INTERACTIVE MODE
 Once python is installed, you can open command prompt and type “python” (without quotation mark) to
write and run python code
 If Python is already properly installed and added to the PATH, you will see something like this
 Now, try to type print(‘hello world!’) and press ENTER.
 Congratulations! You wrote your first program in Python!
RUNNING SCRIPT FROM COMMAND PROMPT
 Writing codes directly through command prompt
can be quite limited
 Thus, let’s try to write a script in a file. One the
(best) way to do this is by using Notepad++ which
can be downloaded from https://notepad-plus-
plus.org/downloads/
 In this Notepad++, change language into Python
 Now, write your hello world program (i.e.,
print(‘hello world’))
 Save the file into your preferred directory.
RUNNING SCRIPT FROM COMMAND PROMPT
 Now that you have your script saved, we can run it through command prompt
 First, open your command prompt
 If the file is in different drive compared to the default one (for example, my default cmd directory is C: but
I saved my python script in drive D: ), type the drive letter followed by colon “:” to change the drive
 Now, change the directory to the folder where you saved the script by using cd command, for example;
RUNNING SCRIPT FROM COMMAND PROMPT
 Now run the command python followed by the name of your scripts. Don’t forget the .py extension!
 Congratulations! Now you can write any python program using notepad++ and run it using command
prompt!
WRITING AND EDITING SCRIPT USING IDLE IDE
 Instead of using notepad++ to write script and using cmd to run it, you can use IDLE IDE which is
installed alongside python installation. Just find program called IDLE in your system and run it
 You can write your script in IDLE window and save it to any directory you preferred
 You can run the script by selecting RunRun Module on the menu bar
ANACONDA
ANACONDA INSTALLATION
 Go to https://www.anaconda.com/products/individual
 Download windows Installer for the version you like (Or any release suitable to the Python version you installed,
if you already installed python separately)
 Proceed with the installation with recommended settings (Note: When the dialog gave you two checkboxes, the
top one being the option to add Anaconda to PATH, follow the recommendation and check THE BOTTOM
CHECKBOX ONLY)
 Once installed, there are two important applications that will be in your system.
 First is called Anaconda prompt, which acts like cmd and helps you to install packages using either Conda or pip
package manager (Note that you can also install packages through Navigator, but you can only use Conda this
way)
 The second is called Anaconda Navigator. When you open this Navigator, you will be shown a lot of IDEs that can
be used. Some of these IDEs may be ready to launch, some others may need to be installed
ANACONDA NAVIGATOR
Tons of
IDEs You
can Use
for Many
languages
Control for Programming
Environments
PYTHON ENVIRONMENT
 When writing a program in python, we can create isolated environment in which we can create python project
(i.e. python program consisting of scripts and other supporting components)
 This allows a structured way creating multiple projects, where the programmer may install specific sets of
packages that are really necessary for each project
 Programmer may even use different python version in different environment
 In cmd, a command “py -m venv env” (without quotation marks) can be executed from a directory to create
virtual environment called venv
 We can enter this virtual environment by changing directory to this environment (using cd venv) and execute
“Scriptsactivate” (without quotation marks)
 Now you can install packages you want for your project stored in that the folder where venv is located
 In Anaconda Navigator, you can create new virtual environment easily using “Environments” button on the left
panel, and select the IDE you want run in this environment via the drop down menu above the list of IDEs
 That being said, for now we will simply use the default environment (“base” or “root”)
IMPORTANT NOTES BEFORE WE START
 Remember, just like a lot of other programming languages, Python is case sensitive!
 Unlike many other programming language, indentation is very crucial in Python scripts.
 When using a “paired symbols” in a line of code such as a pair of double quotes, a pair of single quotes,
parenthesis, etc. make sure that they really are a pair. For example when using parenthesis, make sure
that every opening parenthesis has exactly one closing parenthesis
 A comment is a line of code that will not be evaluated by compiler/interpreter. It is useful to provide extra
information which may help to make the script more readable. In python, a comment is a line that starts
with #
 It is not mandatory, but in python there are several unwritten rules about writing a script. One of them is
to write a variable with two words all in lower case separated by underscore. There are other ‘writing
style rules’, commonly referred as PEP 8 of which the complete list you can find here:
https://peps.python.org/pep-0008/
 Along the journey, we will see a lot of writing styles either being mandatory or highly suggested by
Python community
HOMEWORK 1
2. Try Multiple IDEs for Python and choose one that suits you the best
THANK YOU

Intro to Programming Week 2_Python Installation.pptx

  • 1.
  • 2.
  • 3.
    TWO WAYS TOINSTALL  You can either choose to install Python directly, or through a package manager. One of the most popular one is called Anaconda  Installing Python directly is easier, and only installs additional very lightweight IDE called IDLE. You can write python program by either 1. Write and run it through IDLE 2. Write and run the code directly from command prompt 3. Installing other IDEs and write/run the program from there 4. Write the python code in a notepad or notepad++ and run it through command prompt  On the other hand, direct python installation only installs a package manager called pip, and you will only have access to packages in Python language
  • 4.
    TWO WAYS TOINSTALL  Installing Anaconda also installs python (if python has not been installed yet).  Installing Python directly is a little bit more complicated, and it installs a comparatively more heavy Anaconda navigator. You can write and run python program by 1. Write and run it through IDEs which can be installed from Anaconda Navigator 2. Write and run the code directly from anaconda prompt 3. Write the python code in a notepad or notepad++ and run it through anaconda prompt  On the other hand, python installation through Anaconda installs a package manager called Conda, and you with this you can have access to packages written not only in Python but other languages too.
  • 5.
  • 6.
    PYTHON INSTALLATION  Goto https://www.python.org/downloads/windows/  Download the latest release of Python  Run the installer, and make sure to add python to PATH
  • 7.
  • 8.
    CODING IN INTERACTIVEMODE  Once python is installed, you can open command prompt and type “python” (without quotation mark) to write and run python code  If Python is already properly installed and added to the PATH, you will see something like this  Now, try to type print(‘hello world!’) and press ENTER.  Congratulations! You wrote your first program in Python!
  • 9.
    RUNNING SCRIPT FROMCOMMAND PROMPT  Writing codes directly through command prompt can be quite limited  Thus, let’s try to write a script in a file. One the (best) way to do this is by using Notepad++ which can be downloaded from https://notepad-plus- plus.org/downloads/  In this Notepad++, change language into Python  Now, write your hello world program (i.e., print(‘hello world’))  Save the file into your preferred directory.
  • 10.
    RUNNING SCRIPT FROMCOMMAND PROMPT  Now that you have your script saved, we can run it through command prompt  First, open your command prompt  If the file is in different drive compared to the default one (for example, my default cmd directory is C: but I saved my python script in drive D: ), type the drive letter followed by colon “:” to change the drive  Now, change the directory to the folder where you saved the script by using cd command, for example;
  • 11.
    RUNNING SCRIPT FROMCOMMAND PROMPT  Now run the command python followed by the name of your scripts. Don’t forget the .py extension!  Congratulations! Now you can write any python program using notepad++ and run it using command prompt!
  • 12.
    WRITING AND EDITINGSCRIPT USING IDLE IDE  Instead of using notepad++ to write script and using cmd to run it, you can use IDLE IDE which is installed alongside python installation. Just find program called IDLE in your system and run it  You can write your script in IDLE window and save it to any directory you preferred  You can run the script by selecting RunRun Module on the menu bar
  • 13.
  • 14.
    ANACONDA INSTALLATION  Goto https://www.anaconda.com/products/individual  Download windows Installer for the version you like (Or any release suitable to the Python version you installed, if you already installed python separately)  Proceed with the installation with recommended settings (Note: When the dialog gave you two checkboxes, the top one being the option to add Anaconda to PATH, follow the recommendation and check THE BOTTOM CHECKBOX ONLY)  Once installed, there are two important applications that will be in your system.  First is called Anaconda prompt, which acts like cmd and helps you to install packages using either Conda or pip package manager (Note that you can also install packages through Navigator, but you can only use Conda this way)  The second is called Anaconda Navigator. When you open this Navigator, you will be shown a lot of IDEs that can be used. Some of these IDEs may be ready to launch, some others may need to be installed
  • 15.
    ANACONDA NAVIGATOR Tons of IDEsYou can Use for Many languages Control for Programming Environments
  • 16.
    PYTHON ENVIRONMENT  Whenwriting a program in python, we can create isolated environment in which we can create python project (i.e. python program consisting of scripts and other supporting components)  This allows a structured way creating multiple projects, where the programmer may install specific sets of packages that are really necessary for each project  Programmer may even use different python version in different environment  In cmd, a command “py -m venv env” (without quotation marks) can be executed from a directory to create virtual environment called venv  We can enter this virtual environment by changing directory to this environment (using cd venv) and execute “Scriptsactivate” (without quotation marks)  Now you can install packages you want for your project stored in that the folder where venv is located  In Anaconda Navigator, you can create new virtual environment easily using “Environments” button on the left panel, and select the IDE you want run in this environment via the drop down menu above the list of IDEs  That being said, for now we will simply use the default environment (“base” or “root”)
  • 17.
    IMPORTANT NOTES BEFOREWE START  Remember, just like a lot of other programming languages, Python is case sensitive!  Unlike many other programming language, indentation is very crucial in Python scripts.  When using a “paired symbols” in a line of code such as a pair of double quotes, a pair of single quotes, parenthesis, etc. make sure that they really are a pair. For example when using parenthesis, make sure that every opening parenthesis has exactly one closing parenthesis  A comment is a line of code that will not be evaluated by compiler/interpreter. It is useful to provide extra information which may help to make the script more readable. In python, a comment is a line that starts with #  It is not mandatory, but in python there are several unwritten rules about writing a script. One of them is to write a variable with two words all in lower case separated by underscore. There are other ‘writing style rules’, commonly referred as PEP 8 of which the complete list you can find here: https://peps.python.org/pep-0008/  Along the journey, we will see a lot of writing styles either being mandatory or highly suggested by Python community
  • 18.
    HOMEWORK 1 2. TryMultiple IDEs for Python and choose one that suits you the best
  • 19.