Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

System Implementation: Install Python For Windows

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

System Implementation

Install Python for Windows


Installing Python on Windows will take some important steps :
Step 1): Go to the python official website
at https://www.python.org/downloads/windows/.
Step 2): Choose the latest version of Python releases for Windows
• How to download and install Python Latest Version on macOS / Mac
OS
.

Official Python Page

Step 3): After choosing the correct released version, Click on the
download Python.
Step 4): Click on Install now, and you can add python.exe path.

67
Click on Install

Step 5) : After the installation completed , You will find python is installed
in your system .

Python Installed in system

68
After a successful installation of Python, IDLE(Integrated Development
and Learning Environment) will also be installed on our local computer
alongside some of the packages. For simple programs, we can use IDLE.
Python programs can also be written in a notepad and run from the
command prompt. For this, follow the steps:
1. Open the notepad.
2. Write the code in it.
3. Save the file with the .py extension.
4. Open the terminal/command prompt.
5. For type in the following command >> py filename.py.
6. The output will be displayed.
Example: We have created a file named hello.py with the
content print(“Hello world”).

For large and complex programs, it is more convenient to use a smart


IDE. To set-up Python properly in your system You can prefer to any IDLE
mentioned below.
Different IDLE and Python Programming Environment
1. Atom : Atom is a free and open-source text and source code editor for
macOS, Linux, and Microsoft Windows with support for plug-ins written in
Node.js, and embedded Git Control, developed by GitHub. Atom is a
desktop application built using web technologies. [link
– https://sourceforge.net/projects/atom.mirror/]

Atom Logo

2. PyCharm : PyCharm is an integrated development environment used in


computer programming, specifically for the Python language. It is
developed by the Czech company JetBrains. [link
– https://www.jetbrains.com/pycharm/]

69
PyCharm logo

3. Visual Studio Code : Visual Studio Code is a free source-code editor


made by Microsoft for Windows, Linux and macOS. Features include
support for debugging, syntax highlighting, intelligent code completion,
snippets, code refactoring, and embedded Git. [link
– https://code.visualstudio.com]

Visual Studio Code

4. Spyder : Spyder is an open-source cross-platform integrated


development environment for scientific programming in the Python
language. [link – https://www.spyder-ide.org]

70
Spyder

5. Wing IDE : The Wing Python IDE family of integrated development


environments from Wingware was created specifically for the Python
programming language. [ link – https://wingware.com]

WinG IDE

6. Thonny : Thonny is an integrated development environment for Python


that is designed for beginners. It supports different ways of stepping
through the code, step-by-step expression evaluation, detailed
visualization of the call stack and a mode for explaining the concepts of
references and heap. [ link –https://thonny.org ]

Thonny

We can also use online IDEs. Online IDEs are helpful to code from remote
locations on a different computer, they are also used if our computer does
not have space to download software. We can also share our code online
with others.

Create a Project in Django


Before you begin, you will need to have the following:
• Windows 10 or later
• Python 3.6 or later
• Python pip
Step 1: Opening PowerShell
The first step is to open PowerShell. To do this, press the Windows key
and type PowerShell. Right-click on the PowerShell icon and select Run
as Administrator.

71
PowerShell

open PowerShell

Step 2: Verifying Python Installation


Once PowerShell is open, you can verify that Python is installed by
typing python –version. This will display the version of Python that is
installed.
Terminal command:
72
python --version

Python is installed

Step 3: Upgrading PIP


Next, you will need to upgrade pip. To do this, type python -m pip install
–upgrade pip. This will ensure that you have the latest version of pip
installed.

upgrade pip

Step 4: Creating a Project Directory


Now, you will need to create a project directory. To do this, type mkdir
myproject. This will create a directory called myproject.
(i) Create the directory by utilizing the mkdir command. This command is
a powerful tool that allows you to quickly and easily create a directory in
your system. With this command, you can create a directory in seconds,
making it a great time-saver for any user.
mkdir django_project

73
Create the directory

(ii) Navigate to the Django_Project directory using the `cd` command.


Here, you’ll find all the necessary components to get your project up and
running.
cd django_project

Django_Project directory

Step 5: Creating the Virtual Environment


Next, you will need to create a virtual environment. To create a virtual
environment called myproject.
To do this, type in terminal
python -m venv myproject

python -m venv myproject and ls

Step 6: Activating the Virtual Environment


Now, you will need to activate the virtual environment. To do this, type
venv\Scripts\activate

74
activate the virtual environment

Step 7: Installing Django


This section will teach you how to install Django on your system
using pip. To do this, run the following command:
pip install Django
This will install the latest version of Django, allowing you to start building
powerful web applications easily.

Installing Django

If you wish to install a different version of Django, you can easily specify
the version you desire by following these steps:
pip install django

version of Django

75
Once the installation is complete, you must verify that Django has been
successfully installed. To do this, enter the following command:
django-admin --version

Django version

Step 8: Create the Django Project


Now it’s time to create a project. According to the Django documentation,
a project is a Python package – i.e. a directory of code – that contains all
the settings for an instance of Django. This includes database
configuration, Django-specific options, and application-specific settings.
To create the project, use the command-line utility django-admin that
comes with Django. This command will generate files where you can
configure the settings for your database, add third-party packages, and
more.
Create the project using the following command:
django-admin startproject test_project
Change into the test_project directory:
cd test_project
Type the following command to see the contents in the project directory:
ls test_project
Output:

output

The directory test_project contains Django configuration files. The


manage.py file is especially useful when starting a development server,
which is what you will do in the next step.

76
Step 9: Running the Development Server
Now that the project has been created, it’s time to start the Django
development server.Start the development server using the manage.py
runserver command:
Note: Make sure sure you are in the same directory as manage.py file
after to run manage.py runserver
python manage.py runserver

Start

Now, Go to http://127.0.0.1:8000/ in your web browser. You should see a


page similar to the following screenshot:

Conclusion:
You have come to the end of this article. You learned how to install
Django on Windows, verify the installation, and you also learned how to
create a Django project and start a development server.

77
Step 10: Create app in django
Now as we created the project in django and our django server is up and
running and if now to create app in django project we can achieve it b by
using django inbuit command which will initiate the django app for us.
Note: Make sure before running the command we must inside our project
directory if not then run the below command
cd test_project
now we are inside the test_project and we are ready to create django app
django-admin startapp test_app
Now this command will create app inside our project and we ready to go
with the django project and to know more about django app you can refer
to the article – How to create app in django.

Using DB Browser for SQLite


Launching DB Browser

In Windows the installation of DB Browser does not create a desktop icon. To


explicitly launch the application after installing it, use the windows button
(bottom left of screen) and type in

DB Browser’ in the search bar and selecting the application when it appears.

78
The Initial screen
The initial screen of DB Browser will look something like this, the panes may
be in a different configuration;

There is;

A small menu system consisting of File, Edit, View and Help. Below the menu
system is a toolbar with four options; New Database, Open Database, Write
Changes and Revert Changes. Below the toolbar is a 4-tabbed pane for;
Database Structure, Browse Data, Edit Pragmas and Execute SQL. Initially
these will be quite empty as we haven’t created or opened a database yet. In
general we will see how each of these are used as we go through the lesson with
the exception of the Edit Pragmas tab which deals with system wide parameters
which we won’t want to change.

On the right hand side there are two further panes, at the top is the Edit
Database Cell pane which is grayed out. Below it is a 3-tabbed pane for DB
Schema, SQL log and Remote. We are only really interested in the DB Schema
tab.

79
Initial changes to the layout.
The overall layout of DB Browser is quite flexible. The panes on the right-hand
side can be dragged and dropped into any position, the individual tabs on the
bottom pane closed directly from the pane and re-opened from the menu View
item.

We will make a couple of initial changes to the layout of the screen. These will
be retained across sessions.

1. From the View menu item un-select the ‘Edit Database Cell’ icon to the
left of the text. This will make the pane close and the bottom pane will be
expanded automatically to fill the space.
2.
a. On Windows, From the View menu item select ‘preferences’ and
select the Data Browser tab.
3.

b. On Mac, From the “DB Browser for SQLite” menu item select
‘preferences’ and select the Data Browser tab.

80
Towards the bottom there is a section dealing with Field colors. You will see
three bars below the word Text, to the right there are in fact three invisible bars
for the Background. Click in the area for the Background color for NULL. A
colour selector window will open, select Red. The bar will turn Red. This is
now the default background cell colour that will be used to display NULL
values in you tables. We will discuss the meaning of NULL values in a table in
a later episode.

You can now close the preference window by clicking OK.

Opening a database
For this lesson we will be making extensive use of the SQL_SAFI database. If
you do not already have a copy of this database you can download it from here.

To open the database in DB Browser do the following;

1. Click on the ‘open database’ button in the toolbar.


2. Navigate to where you have stored the database file on your local
machine, select it and click open.

When you open the database, the ‘Database Structure’ tab on the left and the
‘DB Schema’ pane on the right will look very similar. However the ‘DB
Schema’ pane is only there to allow you to see the details of the schema for the
tables. In particular what tables are in the database and the fields and their types
which are in each table.

The ‘Database Structure’ tab on the left allows you to initiate actions on the
tables. If you right click on a table name in the ‘DB Schema’ pane, nothing
happens. However, if you do the same in the ‘Database Structure’ menu you
will be given a set of possible actions. These are the same actions that are
available from the toolbar at the top of the tab.

81
If you select ‘Browse Table’, the data from the table is loaded into the ‘Browse
Data’ pane from where it can be examined or filtered. You can also select the
table you wish to Browse directly from here.

There are options for ‘New Record’ and ‘Delete Record’. As our interest is in
analysing existing data not creating or deleting data, it is unlikely that you will
want to use these options.

Running SQL Queries


We will be running queries extensively in future episodes. For now we will just
provide an outline of the environment.

In the left hand pane if you select the Execute SQL tab, you will be presented
with a three paned window and a small toolbar. The top pane is itself tabbed
with the initial tab labeled ‘SQL 1’. This is the SQL editor pane into which you
will type your queries.

Below is a simple example query and the results.

82
Notice that the query has been written over multiple lines. This is commonly
done to aid readability. The second pane has the tabular results, and the bottom
pane has a message indicating how many rows were returned, how long it took
and a copy of the SQL statement that was executed.

On the toolbar at the top there are eight buttons. Left to right they are:

• Open Tab (creates a new tab in the editor)


• Open SQL file (allows you to load a prepared file of SQL into the editor -
the tab takes the name of he file)
• Save SQL file (allows you to save the current contents of the active pane
to the local file system)
• Execute SQL (Executes all of the SQL statements in the editor pane)
• Execute current line (Actually executes whatever is selected)
• Save Results (Either to a CSV file or as a database view. We will look at
views in a later episode)
• Find (Text in the editor window)
• Find & Replace (Text in the editor window)

Because it is possible to have and execute multiple SQL statements in the same
editor pane, each must be terminated with a ‘;’. If you only have a single

83
statement you don’t need it, but it might be considered best practice to always
include it.

The pane below the editor is the Results pane. The results of running your query
will appear here in a simple tabular format. The bottom pane is for messages
about the execution, either an error message or an indication of how many rows
were returned by the query.

Creating a database
As well as opening (connecting) to existing databases it is also possible to
create new SQLite databases and tables using DB Browser. To create a database
click the New Database button from the main toolbar (also available from the
File menu). You will initially be asked for a name for the database and where
you want to save it. It is saved as a single file. You can choose your own
extension but ‘sqlite’ is recommended. If you do not provide a default, then a
‘.db’ extension will be used. Although the new database is empty, in that there
are no tables in it, the .sqlite file itself is not empty.

Once you have saved the database file the Create Table wizard will open
allowing you to create a table. You can cancel this as we will be going through
the create table process in a later episode.

84
85

You might also like