Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Python Installation

• For Windows user


• Download the latest version from

http:/ / www. python. org/ download/ releases/ 3. 0/ and download the latest version
• Open the installer as administrator
• Check the box “Add to Python X to PATH”
• To access from any where, like in command prompt using “python”
syntax
• Comes with IDLE

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Python Installation
• For Windows user
• Steps to be followed and remembered:
• Step 1: Select Version of Python to Install.
• Step 2: Download Python Executable Installer.
• Step 3: Run Executable Installer.
• Step 4: Verify Python Was Installed On Windows.
• Step 5: Verify Pip Was Installed.
• Step 6: Add Python Path to Environment Variables (Optional)

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Python Installation

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Python Installation
• Working with Python Python Code Execution:
• Python’s traditional runtime execution model: Source code you
type is translated to byte code, which is then run by the Python
Virtual Machine (PVM). Your code is automatically compiled, but
then it is interpreted

Source code extension is .py


Byte code extension is .pyc (Compiled python code)

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Python Installation
• For Linux users
• Pre-installed
• To check
$ python -V
Python 3.0b1
➢ Python installed
$ python -V
bash: Python: command not found
➢ Python not installed
• Compile Python from the source code (http:/ / www. python. org/
download/releases/ 3. 0/ ) and install it.
• Install the binary packages using the package management software that
comes with OS
DEPARTMENT OF APPLIED PHYSICS,
EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Python: Basics
• Variables, Data types, Operators
• Arrays
• Flow Control
• Methods
• File Handling
• OOPS

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Python Programming: First Step
• Python is also interpreter
• Interpreter is the program need to run the Python code and scripts
• It is a layer of software that works between program and computer
hardware to execute the code
➢ Open command prompt ➢ Open the IDLE
➢ Write ➢ Write
➢ python.exe ➢ print(‘hello world’)
➢ print(‘hello world’) ➢ Run the
➢ >> hello world ➢ >> hello world
• To exit the prompt, press ctrl-d if you are using IDLE or are using a
Linux/BSD shell.
• In case of the Windows command prompt, press ctrl-z followed by
enter key.
DEPARTMENT OF APPLIED PHYSICS,
EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Development Tool
• Editors allows the programmer to enter the program source code and
save it to files.
• Most programming editors increase programmer productivity by using colors to
highlight language features.
• The syntax of a language refers to the way pieces of the language are arranged
to make well-formed sentences.
• To illustrate, the sentence
• The tall boy runs quickly to the door. Not correct
• Boy the tall runs door to quickly the. syntactically
• Programming languages have strict syntax rules that programmers must follow
to create well-formed programs.
• Some syntax-aware editors can use colors or other special annotations to alert
programmers of syntax errors during the editing process.

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Development Tool
• Compilers translates the source code to target code.
• The target code may be the machine language for a particular platform or
embedded device.
• The target code could be another source language;
• For example, the earliest C++ compiler translated C++ into C, another higher-level
language.
• The resulting C code was then processed by a C compiler to produce an executable
program.

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Development Tool
• Debuggers allows a programmer to more easily trace a program’s
execution in order to locate and correct errors in the program’s
implementation.
• With a debugger, a developer can simultaneously run a program and see which
line in the source code is responsible for the program’s current actions.
• Debuggers are valuable for locating errors (also called bugs) and repairing
programs that contain errors.

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Development Tool
• Interpreters is like a compiler, in that it translates higher-level source
code into target code.
• Compiler produces an executable program that may run many times with no
additional translation needed, an interpreter translates source code statements
into machine language each time a user runs the program.
• Interpreted languages are often referred to as scripting languages.
• In general, compiled programs execute more quickly than interpreted programs
because the translation activity occurs only once.
• Interpreted programs can run as is on any platform with an appropriate
interpreter
• Interpreted languages are better suited for dynamic, explorative development
which many people feel is ideal for beginning programmers.
• Popular scripting languages include Python, Ruby, Perl, and, for web browsers,
Javascript.

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Python Programming: Development
Environment
• To develop code ‘Notepad’ is not a obvious choice
• Does not support syntax highlighting
• Does not support indentation
• There are many more Integrated Development Environment
(IDE)
• Eclipse
• PyCharm
• Notepad etc
• IDE is a Graphical User Interface (GUI)

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Features of Python IDE
✓Code editor: Python IDE
• Edit the text 1. PyCharm
• Standalone or integrated
2. Spyder
✓Syntax highlighting
• Marks the syntaxes 3. Pydev
✓Auto completion 4. Rodeo
• Minimize the time consumption 5. Sublime Text
✓Debugger 6. Wing
• Test and debug the source code
7. Eric
✓Compiler 8. Atom
• Translate to different language
9. Thonny
10. IDLE
DEPARTMENT OF APPLIED PHYSICS,
EVEN SEMESTER
UNIVERSITY OF CALCUTTA
jupyter notebook

Install Jupyter Notebook on Windows


• Using pip
• python -m pip install --upgrade pip
• python -m pip install jupyter
• jupyter notebook

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Python Interactive Shell
• A program can be execute from interactive shell
• A command can be typed into the Python Shell pane, and the interpreter
will attempt to execute them
• The interpreter prompts the user for input with three greater-than symbols
(>>>).
• Any lines without the >>> prefix represent the interpreter’s output, or
feedback, to the user. >>> print('hi')
File "<stdin>", line 1
print('hi')
>>> print("Hello!") ˆ
Hello! IndentationError: unexpected indent

• In Python the indentation of statements is significant and the interpreter


generates error messages for improper indentation.
• Understand more features later…

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Check Version
• Check the python version
py --version python3 --version

python --version
Windows Traceback (most recent call last): File Unix/macOS
, line 1, in <module> NameError: name 'python' is not
defined

• Check the pip version


py -m pip --version python3 -m pip --version

Windows Unix/macOS

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Installing pip
• If pip is not automatically installed
• first try to bootstrap it from the standard library
py -m ensurepip --default-pip python3 -m ensurepip --default-pip

• If that
Windows still doesn’t allow you Unix/macOS
• Download the script, from https://bootstrap.pypa.io/get-pip.py.
• Open a terminal/command prompt, cd to the folder containing the get-pip.py file and
run:
> py get-pip.py python get-pip.py

Windows
Unix/macOS
• Upgrading pip
<path>:> py -m pip install --upgrade pip $ python -m pip install --upgrade pip
DEPARTMENT OF APPLIED PHYSICS,
EVEN SEMESTER
Windows UNIVERSITY OF CALCUTTA
Unix/macOS
Install Packages
• The most common usage of pip is to install from the Python
Package Index (PyPI) using a requirement specifier
• requirement specifier: package name followed by version specifier
C:> py -m pip install <project name == version>
[...]
Successfully installed <project> "SomeProject"
"SomeProject==1.4"
"SomeProject>=1,<2"
$ python -m pip install <project name == version> "SomeProject~=1.4.2"
[...]
Successfully installed <project>

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Install Packages
• Install a package from GitHub

pip install https://github.com/<file path>

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA
Uninstall Packages
• To uninstall a package globally in Windows:
1.Open a command window by entering ‘cmd’ in the
Search Box of the Task bar
2.Press Ctrl+Shift+Enter to gain Administration (Admin)
privileges
3.pip uninstall <packagename>
• To uninstall a package globally in Linux:
1.Open a terminal window
2.sudo su pip uninstall <packagename>

DEPARTMENT OF APPLIED PHYSICS,


EVEN SEMESTER
UNIVERSITY OF CALCUTTA

You might also like