Getting Started with Python and the PyCharm IDE

Similar documents
Writing and Running Programs

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

Word 2007/10/13 1 Introduction

Lab 1: Accessing the Linux Operating System Spring 2009

Setting up PyCharm Professional

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

CS1110 Lab 1 (Jan 27-28, 2015)

Forms for Palm OS Version 4 Manual

CHAPTER 1 COPYRIGHTED MATERIAL. Getting to Know AutoCAD. Opening a new drawing. Getting familiar with the AutoCAD and AutoCAD LT Graphics windows

Forms Desktop for Windows Version 4 Manual

Wimba Pronto. Version 2.0. User Guide

In the first class, you'll learn how to create a simple single-view app, following a 3-step process:

Computer Basics: Step-by-Step Guide (Session 2)

Computer Essentials Session 1 Lesson Plan

My First iphone App. 1. Tutorial Overview

IT Essentials v6.0 Windows 10 Software Labs

How To Capture Screen Shots

The Fundamentals. Document Basics

A computer program is a set of instructions that causes a computer to perform some kind of action. It isn t the physical parts of a computer like the

ChemSense Studio Client Version 3.0.7

You can use the WinSCP program to load or copy (FTP) files from your computer onto the Codd server.

Version June 2016

How to Use Google. Sign in to your Chromebook. Let s get started: The sign-in screen.

CheckBook Pro 2 Help

CME E-quotes Wireless Application for Android Welcome

EXCEL BASICS: MICROSOFT OFFICE 2007

Arduino IDE Friday, 26 October 2018

How To Capture Screen Shots

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

EXCEL BASICS: MICROSOFT OFFICE 2010

Getting started with Python

The Python Mini-Degree Development Environment Guide

JCCC Virtual Labs. Click the link for more information on installing on that device type. Windows PC/laptop Apple imac or MacBook ipad Android Linux

Code::Blocks Student Manual

Impossible Solutions, Inc. JDF Ticket Creator & DP2 to Indigo scripts Reference Manual Rev

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

Creating Vector Shapes Week 2 Assignment 1. Illustrator Defaults

Wimba Pronto. Version 2.1. User Guide

Semester 2, 2018: Lab 1

Sync User Guide. Powered by Axient Anchor

SharePoint: Fundamentals

Windows 10 Creators Edition Tips & Tricks. These New Hidden Features Will Save You Time and Money

SolidWorks Intro Part 1b

Applied ICT Skills MS Windows

Introduction to Microsoft Office 2016: Word

Firewalls can prevent access to the Unix Servers. Please make sure any firewall software or hardware allows access through Port 22.

SharePoint: Fundamentals

GRS Enterprise Synchronization Tool

Part 1: Understanding Windows XP Basics

Guide to User Interface 4.3

Understanding the Interface

Tabbing Between Fields and Control Elements

Windows 10 Essentials

The following instructions cover how to edit an existing report in IBM Cognos Analytics.

Comodo Chromium Secure Software Version 36.1

CommCare for Android Smartphones

1) Log on to the computer using your PU net ID and password.

Startup Notes for Standard CMD 2015.x Setup

Navigate to Cognos Cognos Analytics supports all browsers with the exception of Microsoft Edge.

Slide 1 CS 170 Java Programming 1 Duration: 00:00:49 Advance mode: Auto

Mehran Sahami Handout #5 CS 106A September 26, 2018 Downloading Eclipse

You might think of Windows XP as a set of cool accessories, such as

Key File Generation. November 14, NATIONAL STUDENT CLEARINGHOUSE 2300 Dulles Station Blvd., Suite 220, Herndon, VA 20171

Module 3: Working with C/C++

Parallels Remote Application Server

Outlook - an Introduction to Version 2003 Table of Contents

Looking at the Internet with Google Chrome & Firefox. Scoville Memorial Library Claudia Cayne - September, 2010

Handout Objectives: a. b. c. d. 3. a. b. c. d. e a. b. 6. a. b. c. d. Overview:

FREEDOM-Pad Installation and Operation

Citrix User Guide Version 2.2. Table of Contents. Citrix on a PC... 1

My First Cocoa Program

Intro to Excel. To start a new workbook, click on the Blank workbook icon in the middle of the screen.

Lesson 1. Importing and Organizing Footage using Premiere Pro CS3- CS5

Getting Familiar with Microsoft Word 2010 for Windows

GETTING STARTED. 3. Once in the Portal, click on the WebEx icon in the upper right corner of the screen.

QST Mobile Application for Android

My First iphone App (for Xcode version 6.4)

IC3 Spark. Courseware FOR REVIEW ONLY

Navigating Windows 10 Windows 10 is the most recent version of the Microsoft Windows operating system.

Microsoft SharePoint is provided by Information Services for staff in Aberystwyth University.

FTP Frequently Asked Questions

Assignment 1. Application Development

SuperNova. Magnifier & Speech. Version 15.0

Windows 10 Quick Tips

DOCUMENT IMAGING REFERENCE GUIDE

Multi-Find/Change 3.0 Manual

Backup App V7. Quick Start Guide for Windows

Mehran Sahami Handout #5 CS 106A September 27, 2017 Downloading Eclipse

Discovering Computers & Microsoft Office Office 2010 and Windows 7: Essential Concepts and Skills

SolidWorks 2½D Parts

Parallels Toolbox User's Guide

Odyssey Quick Start. Quick Links: Launch Pad and Assignments Portfolio and Reports FAQs For Parents GUIDE FOR STUDENTS AND PARENTS

TourMaker Reference Manual. Intro

Workshare Desktop App. User Guide

Opening Microsoft Word. 1. Double click the Word 2016 icon on the desktop to launch word.

Click Here to Begin OS X. Welcome to the OS X Basics Learning Module.

Parallels Toolbox for Windows User's Guide

Gradebook User Guide. PowerTeacher

Copyright 2018 MakeUseOf. All Rights Reserved.

NetLogo Tutorial Series: Langton's Ant. Nicholas Bennett Grass Roots Consulting

Transcription:

New York University School of Continuing and Professional Studies Division of Programs in Information Technology Getting Started with Python and the PyCharm IDE Please note that if you already know how to write and run Python programs, you do not need these instructions. However, you may find my configuration of PyCharm to be helpful. PyCharm is a popular developer tool. I will be using PyCharm for class demonstrations, including using its debugger. Please complete these instructions before our first class. Read and follow the steps carefully to understand how PyCharm works and to avoid any confusion. The software development process requires two programs: a) Python. We will use Python 3, though you are free to use Python 2 if you prefer. b) a text editor or IDE. We will use the PyCharm IDE, though you are free to use another IDE or text editor if you prefer. An Integrated Development Environent (IDE) is a text editor that understands code, provides smart searching and organizing, and oftentimes a debugger. We will use PyCharm's integrated debugger in class. 1. Install Python. In this step, Python 3 will be installed onto your Mac or Windows computer. Note that if you are intending to use Python 2, this version comes pre-installed on the Mac operating system. Also if you have installed in the Mac Developer Tools (an advanced toolset), Python 3 should have been installed along with it. Windows does not come with either version preinstalled. a. Visit http://python.org b. Roll over Downloads > [Windows or MacOS] and click button marked 3.x.x, where 3.x.x will be a number such as 3.6.4, 3.7.2, etc. If instead of rolling over, you end up clicking on the name of the operating system, you'll see a page titled Python Releases for [Windows or Mac OS]. Click on the very first link, Latest Python 3 Release - Python 3.x.x, where 3.x.x will be a number such as 3.6.4, 3.7.2, etc. The latest release is best. c. A file should download; double-click the file and follow the instructions. For Windows, check the box that says 'Add Python 3.x to PATH' (where 3.x is 3.6, 3.7, etc. -- a number starting with 3. (If you see such a selection for Mac OS, please also check that.) d. Once installed, open a new Command Prompt (Windows) or Terminal (Mac) session and check the Python version:

i. On Mac: click the magnifying glass and type Terminal, then hit enter or click on the word Terminal listed under "Top hit". A white box with black type should appear, ending in a $ prompt and a small rectangular cursor. The prompt may be similar to this one: Last login: Wed Sep 27 14:39:46 on ttys001 myuser:~ myuser$ Your username/home directory name would stand in place of myuser above. Please do not search for Python or click on Python 3.x (Desktop App) or Python Launcher. These are useful tools, but are not part of our intended approach. ii. On Windows: click in the search box at the lower left of the Desktop, or click Start > Run and type cmd. Click on the Command Prompt button/icon if necessary. A black box with white type should appear, ending in a > prompt and a blinking cursor. C:\Users\homedir> Your username/home directory name will stand in place of homedir above. Please do not search for Python or click on Python 3.x (Desktop App) or Python Launcher. These are useful tools, but are not part of our intended approach. iii. Click in your new window and type the following text at the prompt (use "capital V"): python -V You should see python 3.x.x number displayed (where 3.x.x will be a number such as 3.6.4, 3.7.2, etc.), followed by another prompt. Here are some possible error responses to python -V: If you see python 2.7 or similar number starting with 2 and you are on a mac, try python3 -V instead. this works, then use python3 instead of python in each step going forward. Keep in mind that if you must use python3 to see the version 3.6.2 (or 3.x version) displayed, then you must use python3 instead of python for every command going forward. If you use python you'll be running the 2.7 version, which behaves differently and will cause sometimes confusinge errors. If you see an error message, make sure you've opened up a new Terminal or Command Prompt window, and that you're typing the above correctly. If you still don't see python 3.6.2 or another version number starting with 3, please let me know.

If your window displays a >>> prompt (or you see a great deal of text, followed by >>>), then you have entered the Python interactive prompt, which we will cover later. Please type exit() to return to the regular command prmopt as described above. If you see 'python' is not recognized as an internal or external command or command not found, then python was not put into your operating system's search path (i.e. you did not check the checkbox). You can launch python with the py command, which has been reported to work on Windows systems: py -V If py works for you but not python, then please use py at the command line in all places where you are asked to use python. (This is functionally identical and does not have to be corrected. However, if you wish to be able to execute using python, you can try re-installing python and making sure to check the Add Python 3.6 to PATH). 2. Download and Install PyCharm. (note: if you have PyCharm already installed, skip to 'Install PyCharm Settings', next) a. Visit the download page at https://www.jetbrains.com/pycharm/download b. Under Download PyCharm, make sure that your operating system (Windows, macos or Linux) is selected c. Choose Community Edition (Professional Edition will require a purchase after a trial) d. Download will begin, PLEASE IGNORE the install video instructions (or any other instructions) e. Once downloaded, doubleclick the downloaded file i. On Mac: a window will appear suggesting that you drag the PyCharm icon ("PC") to your Applications Folder -- you can do so right in that window (you may need to enter a password, or confirm that this program is safe to run -- it is!). Once the program is in Applications, you can also create a shortcut to the application if you wish, by dragging it from Applications to your Dock (the horizontal bar at the bottom of your screen with icons that launch programs). You can also create a Desktop shortcut by dragging the icon from Applications while holding down the Cmd+Option keys (so that a swoopy arrow indicating a shortcut is displayed) to the Desktop. (If you don't see a swoopy arrow, the application will be moved to the Desktop, which you do not want.) ii. On Windows: follow the installer steps and accept all defaults. During the install process you can choose to have a shortcut placed on your Desktop. You can also launch PyCharm using the search or Start > Run box.

3. Launch and configure PyCharm. In this step, we will configure PyCharm with a custom settings file that I will provide. These settings specify a dark color scheme, large font and suppresses many of the warnings, popups and completion alerts, which PyCharm defaults to. Unless you have a specific objection to any of this, please complete the below steps for configuring PyCharm. a. Download the custom settings file for your computer. http://davidbpython.com/pycharm_pc.settings http://davidbpython.com/pycharm_mac.settings Clicking on the link should activate your browser and start the download (a very small file); you may want to right-click and select Download as Choose a location where you can easily find the file, such as the Desktop. Please don't open the settings file. b. Launch PyCharm. Click the shortcut or the PyCharm program icon to launch PyCharm, or type PyCharm into your OS's search box (on Windows this may be the Start > Run box, or just the search box on the Desktop; click on JetBrains PyCharm Community Edition; on Mac, use the magnifying glass at the top upper corner of your screen and select PyCharmCE) -- PyCharm launches and presents a small 'Welcome to PyCharm Community Edition' dialog box. If this is your first time opening PyCharm, you may see a medium-sized 'Initial Configuration' dialog box. Please skip this step. If you have opened this copy of PyCharm before, you may see an open project (a few windows including a code window) that fills the whole screen, rather than a smaller dialog box. Go to File > Close Project to close the current project; you should then see the 'Welcome to PyCharm Community Edition' dialog box). c. Save Default PyCharm Settings. Before we configure PyCharm, let's save settings, in case you'd like to return to the defaults. i. Click Configure > Export Settings ii. Leave all boxes checked iii. Choose a save location, or use the default iv. Click OK. Record the location or move this file in a location where you can retrieve it later in case you want to restore PyCharm settings defaults. d. Import the custom PyCharm Settings. As mentioned, importing these settings will change the look of PyCharm to a "dark" theme, as well as remove a lot of distracting popups and warnings. i. Click Configure > Import Settings ii. Find the file you saved in the 'Download the custom settings file' step iii. Leave all boxes checked and click OK iv. PyCharm will indicate that it needs to restart -- say OK v. After PyCharm restarts, it should present the same Welcome dialog, but using a dark color scheme

vi. From now on, PyCharm will remember these settings -- you will not need to take this step again The dark color scheme is designed to be easy on the eyes, but not everyone prefers it. I suggest you complete these instructions before considering a light color scheme, and if you prefer a light color scheme you can reverse the colors as shown below. (Unfortunately, switching color schemes also restores certain warnings that flash on and off as you type, denoting errors even before you're finished typing, which my settings are designed to eliminate. If you prefer the light color scheme and want to turn off these warnings, let me know -- I can help you find the settings you would need for this.) To restore the "black on white" color scheme: 1) Choose Preferences (Mac) or Settings (Windows). 2) Go to Appearance and Behavior > Appearance 3) For Theme, click Default (Mac) or IntelliJ (Windows) and click Apply Note: the above instructions describe initial setup and usually have to be taken only once. The next steps will be performed several times during the semester. We'll start with Step 4 each week when we want to start a new project (I suggest creating a new project each week to keep your lab scripts, test scripts and homework scripts organized.) We'll use Step 5 to start a new Python program (a lab exercise or homework assignment). 4. Start a new PyCharm project. A PyCharm project can be considered as a group of files in a folder. When we create a new project, PyCharm will show us where this folder will be created (we can also choose an existing folder). We should name the folder after the project name. As mentioned above, I recommend you create a new project named session_1, session_2, etc. for each week's work. However, use whatever naming scheme works best for you. a. Click on Create a New Project. PyCharm displays two blanks -- Location and Interpreter. i. Location 1) PyCharm suggests a location in a special folder called PycharmProjects in your home directory. You can use this location or choose a different one by clicking the ellipsis ( ) to the right of the Location blank, or by typing out another path. Although PyCharm will keep track of this location, you will want to note it down for future reference. 2) If you are working with the default, change the value after the last slash to session_1. 3) If you have selected a different folder location than the default, add /session_1 (Mac) or \session_1 (Windows) to the end of your selected location.

ii. Interpreter: this step links your project to your installation of Python. Use the dropdown to ensure that Python 3 is selected (unless you have chosen to use Python 2 for this course). 1) to identify Python 3 (or Python 2), look in the path for 3.x.x (or 2.x.x), where x is another number, for example 3.6.3 or 2.7.10 2) on a Windows PC, if you have installed only one version of Python, that version should be included in the path 3) on a Mac, you may see the default Python 2.x.x version selected. Click the dropdown and select the 3.x.x version b. Click Create. PyCharm should open a larger window with a rectangular panel on the left. If you see the warning "the folder is not empty", this means that you didn't specify a new folder. Unless you're redoing this step, you'll want to start with an empty folder. Click No and then when the larger window opens up, click File > Close. Repeat step a. (previous step) and make sure that you are adding a new folder name to the path in the Location: blank. c. By default, PyCharm shows a "Tip of the Day" at startup. If you'd prefer not to see this each time you start, simply uncheck the "Show these at startup" box. Click Close on this box. d. The left-side window is the project view -- there you can see the project folder and files in the project. If this is a new project, the folder will be empty. External Libraries lists any installed Python libraries you may be using in the project -- not meaningful to us for this step. e. You can open and close the project view with Cmd-1 / Alt-1. 5. Write a new Python program. Program source code is written in "plain" (unformatted) text. We will write this text file inside PyCharm, then have PyCharm feed it to Python to run the program. a. Click File > New (not File > New Project) If New is greyed out, you may have clicked on External Libraries. Click on the small project folder on the left. b. A very small list appears -- choose Python file. c. Name your file hello.py or whatever you prefer. d. Click OK -- the file appears under the project folder in the project view (click the tiny triangle to see it), and also appears as a tab in the main window.

e. Create your first "hello, world!" app by entering the following Python code, starting with the Unix "shebang" line: #!/usr/bin/env python print('hello, world!') Note that if you had to use python3 -V above, first line should be #!/usr/bin/env python3 f. You can save your script with Cmd-S (Mac) or Ctrl-S (Windows), although it appears that you do not need to do so, because PyCharm saves projects (and the files within) automatically. g. You may see a message at the top of your program reading "No Python interpreter configured for the project". I'm not entirely sure why you would see this message if you selected a version of Python in Create a New Project > Interpreter, but if you do, click the link and select an interpreter (as described under that step above). This choice should apply to all subsequent projects that you create. 6. Run the Python program. I prefer that you run your programs in a Terminal / Command Prompt window in PyCharm (rather than the Run window). In the Terminal window approach you are asking the operating system to run your code directly (with Run, PyCharm acts as an intermediary). a. To open the Terminal window, you can hit Cmd-T or Alt-T -- a horizontal rectangular panel appears at the bottom, with a Command Prompt for your operating system (note that it is the same prompt we used to test the python version with python -V. b. Drag the top of the rectangular panel upward so it is larger. You can choose the size to view, and adjust it depending on your situation and what needs to be visible. As you work, you will be switching back and forth between the edit window and the Terminal window. I prefer a large Terminal window and I pop back and forth between windows. We will demonstrate this in class. c. At the prompt, type the following: python hello.py (or use the name you saved with in the prior step). You should see the output of the program. Remember that if you used python3 for your initial test of python, you'll be using python3 hello.py. This is important because the 2.7 version of python is similar but not the same as the 3.6 (or 3.x number) version and It can be difficult to see the difference. d. To make clear output (sometimes vital to smooth progress and understanding) issue a 'clear' command before the python command: i. Mac OS: clear; python hello.py ii. Windows: cls & python hello.py You should see the output of the script clearly displayed by itself at the top of the page.

7. Double-check the Python version. Some students get this far without realizing that they are using Python 2.7 (or 2.x number) instead of the 3.6 (or 3.x number) version. Rewrite your code so it looks like this: #!/usr/bin/env python import sys print('hello,' + sys.version) You should see hello, 3.6.2 (v3.6.2:5fd3. or a number after 'hello, ' that starts with 3. If you are seeing a 2 number instead, you either need to remember to use python3 when you are running the program in the Terminal window, or we need to adjust your computer's PATH variable to point to python 3 -- please get in touch with me if you think you are using ver. 2. 8. Edit, switch, re-run, switch, edit It's very helpful to develop a keyboard-based workflow that will allow you to run through the development cycle repeatedly, without having to hit one more key than necessary. a. Click in the edit window and make an edit to your script (change world! to weird!) b. Use Cmd-T (Mac) or Alt-T (Windows) to open the Terminal window c. Hit the Up Arrow to bring up your last command, then hit Enter. Or retype the commands in the step above. You'll see your program output. d. Use Alt-T (Windows) to close the Terminal window. Window focus should return to the edit window. e. Make an edit to your script (change weird! to python!!!) f. Use Cmd-T or Alt-T to open the Terminal window g. Hit the Up Arrow to bring up your last command, then hit Enter. View the changed result. h. Use Cmd-T or Alt-T to close the Terminal window. Window focus should return to the edit window. i. Lather, rinse, repeat! If you see any errors, anomalies, or if anything seems confusing in these instructions, please let me know as soon as possible. You'll be helping others if you do (or allowing others to be confused if you don't!). [continued]

Appendix: changing PyCharm font size or color Font size: I have deliberately chosen a large the font size, so students new to programming will pay close attention to every character in their code and output. However, a large font size means fewer lines of your program will be visible. To change the font size: Mac: Preferences > Editor > Font and change Size. Windows: File > Settings > Editor > Font and change Size. Please note that the Terminal font size will use the same font size as the editor window, however you may not see this change until you close the window (by clicking the red 'X', not the keyboard shortcut) and reopening it. Dark color theme: I prefer the colored text on black background because it is easier on the eyes. If you prefer a white background, it is possible to change the theme without activating some additional settings that sometimes change when you attempt this. Let me know if you'd like to change your color scheme and we can work out the best way to do this. Congratulations!