0% found this document useful (0 votes)
141 views

Installing and Using Python

To develop Python programs, you can use an IDE like PyCharm or Eclipse, or a text editor. The document recommends installing the latest version of Python from python.org and then downloading and installing the latest version of PyCharm Educational Edition from jetbrains.com. It provides instructions on creating a PyCharm project, naming and writing code for a file, running the file, using the PyCharm console to run commands, and running Python files from the Windows command prompt.

Uploaded by

Keshav Chopra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views

Installing and Using Python

To develop Python programs, you can use an IDE like PyCharm or Eclipse, or a text editor. The document recommends installing the latest version of Python from python.org and then downloading and installing the latest version of PyCharm Educational Edition from jetbrains.com. It provides instructions on creating a PyCharm project, naming and writing code for a file, running the file, using the PyCharm console to run commands, and running Python files from the Windows command prompt.

Uploaded by

Keshav Chopra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Installing and Using Python

To develop Python programs you can use:


1. IDE (Integrated Development Environment) – like PyCharm or Eclipse
2. IDLE (Integrated Development and Learning Environment) – an IDE that is included with
the Python distributions for Windows and Linux.
3. Text Editor

First install the latest version of Python, from https://www.python.org/downloads/. At the time of
this writing the latest version is 3.8.1. You will be using Python’s IDLE very little, just to get an
idea of how to use it.

Throughout the course you are going to be using PyCharm IDE, and therefore through this
lecture you will learn how to Install and use PyCharm.
PyCharm Educational Edition  is a free editor which you can use for writing Python programs.
Download and install the latest version from https://www.jetbrains.com/pycharm-edu/
From jetbrains.com/education click on Download and then click on Python.
The new window will display the Pycharm logo and the latest version. At the time this document
was written the latest version was 2019.3. Click on Download and follow the instructions to
download PyCharm. On the Installation Options select:
1. 64-bit launcher shortcut,
2. Latest Python version (3.8 or later), and
3. create associations .py
The whole process should not take more than 10 minutes.
Run Pycharm and select:
4. Do not import settings
5. Accept the Privacy Policy
6. Data Sharing – Don’t send
7. Are you a learner or Educator – learner
8. Start using Edu Tools
PyCharm provides you with a better environment to write and run your programs using Python.
The Python Console of PyCharm provides you also the choice to run commands or even
programs using command line.

After you download and install PyCharm, it would be a good idea to create a shortcut on your
desktop.

The next steps will show you the basics of how to use Pycharm to code and run Python
programs.
The first part shows you how to use PyCharm’s IDE and the second the use the Console
Part A- Using PyCharm IDE

Step 1 – Create a Project


The first thing you need to do, after you install PyCharm, is to create a Project so you can store
all your programs. To do so, run PyCharm and in the Welcome screen click on Create New
Project.

You will then be presented with the New Project window. In the Location: text bar, type
H:\Python and click Create. PyCharm will create a Virtual Environment.

With this step you created a project named Python on the H: drive of Centennial College, and
this where you will be saving all your Python files. If you wish, you may select a different drive.
Step 2 – Name your file
You can now start naming and writing the code of you program/file. You can do this in two ways.
1. Right-click on the Python project you created and select New and from there Python File.

2. In the menu bar, select File – New… – Python file.


No matter which method you used, you will be presented with the New Python file window
where you can name your file.

You are going to store all your Python files in the project named Python. So, try to give
meaningful names based on the function of the program.
For example the first program you will write, will output the word Hello, thus would be
meaningful to name the file “Hello”.
To give a name to your program, in the Name textbox of the New Python file window, type the
name and hit the <Enter> key.
Step 3 – Type the code
You will now be presented with the PyCharm editor window (top-right pane), where you can
start typing your code.

\
In the editor pane type the statement

print(‘Hello!’)

Step 4 – Running the File


The file named “Hello” has just one statement: print(‘Hello’).
To run this program, click any of the green arrows , or right-click in the editor window and
select Run ‘Hello’. The run button may not work if it is the first time you run the file. In such a
case right-click anywhere on the editor’s pane and select Run ‘Hello’.
The program will run and the output will display in the output pane, which is the lower pane.

After you run your file, the program is saved in the project you created with the name Hello.py
Part B – Using PyCharm’s Console

You can use PyCharm’s console to run a single command or even a group of commands.

Step 1 – Enter Python’s Console


To enter the console mode (interactive), at the bottom bar, click on Python Console, and your
PyCharm window will now look similar to the one below, where the console editor is active at
the bottom left side.

The triple arrows >>> is the Python’s console prompt, and is the indication that Python Console
is running.

You can now start typing your commands (statements) at the Python Console prompt.
Step 2 – Enter statement
At the prompt (>>>) type print(‘Hello!’) and then hit the <enter> key.
The statement would execute and would display the output on the next line.
It would then display the >>> prompt again so you can enter the next command. The left-bottom
corner of your window should look like the following figure.

Running a Program in the Interactive mode


If you need to run a program in the interactive mode:
1. At the >>> type the first statement
2. Press <Shift><Enter> and the prompt will become three dots (…)
3. At the new prompt … type your new statement
4. Keep adding the statements and when you are done hit <Enter>
5. The statements will run as a program.

Example:
>>> print('What is your name', end=' ') <shift><enter>
… name = input() <shift><enter>
… print('Hi', name+’!’) <Enter>

What is your name>? Petros


Hi Petros!

Clear the Console Screen


To clear the console screen click on the icon
Quit Command Line Interpreter
To exit Python Command line Interpreter, type quit
>>>quit()

Find Errors
To find any errors in your code using Pycharm, in the menu bar select
Code | Inspect code…
And then select the file to be inspected

For more information about the PyCharm 2019 settings visit:


https://www.jetbrains.com/help/pycharm/installation-guide.html
Running a File from Windows Command Prompt
After you created a Python file, you can run the program using Windows.
Assuming you saved your file in H:\Python, to run the file “Hello.py” follow the next steps:
1. In the search box of Windows 10, type cmd to open a DOS window.
2. At the command prompt, change the current directory to the directory that contains your
Python files. If you followed the previous instructions it should be H:\Python.
3. First change drive, by typing the drive letter followed by a colon (:), H:, and hit the
<enter> key. The prompt now should be H:\>
4. After the > symbol type: cd Python
5. Your prompt now should be H:\Python>
6. Type the filename with the extension .py to run the file and hit the <enter> key.
H:\Python> hello.py <Enter>

In the following screen-shot F: drive was used instead of H:

You might also like