Advanced Python Getting Started

[Pages:19]Advanced Python

Getting Started

Welcome ? these instructions are provided to help out where needed ? you do not need to follow all the sections here. But please read the start of each section to determine whether you might need to follow the steps to get completely set up.

Table of Contents: ? Required Software ? Installing the Python Interpreter from Anaconda ? Installing the PyCharm Editor/IDE ? Updating Anaconda and PyCharm ? Configuring PyCharm Fonts and Colors ? Downloading Course Files ? Setting PyCharm to work with Anaconda ? Exploring PyCharm ? Using the PyCharm Debugger ? Using Jupyter Notebook

Required Software

You are required to install and be able to use: ? a Python distribution. I am recommending Anaconda Python. ? a text editor or IDE. I am recommending PyCharm. ? Jupyter Notebook, another tool for writing and running programs.

You may choose to use an alternative Python distribution or IDE that you already have installed; in that case you would not need to install any additional software for this class.

However if you don't want to use Anaconda, you must install the following Python modules: ? requests, a web client library ? bs4 (Beautiful Soup), a web scraping library ? pandas, a data processing library ? matplotlib, a data visualization library ? Jupyter notebook (this is not a module but does need to be installed)

Let me know if you have any issues installing these modules (installing these is required for nonAnaconda users only - Anaconda includes them).

Installing the Python Interpreter from Anaconda

If you already have Anaconda or another version of Python installed, you may skip to "Installing the PyCharm Editor/IDE".

If you don't have it, I recommend Anaconda Python: ? a popular distribution of Python ? includes the Python interpreter ? adds useful tools for learning and collaboration, such as Jupyter notebook ? adds many useful modules for finance, web and scientific computing ? requires 3-4GB of space on your computer's disk (you should have at least 5-8GB available on disk before installing). If you do not have this much disk space available, let me know

1. Check the amount of available disk space on your computer.

a. On Mac: i. open a Finder (file listing) window and display a folder of files (for example, your Desktop, but not "All My Files") ii. Look at the bottom of the window - you should see XX GB available

b. On Windows: i. in the search box, do a search for This PC, or look for it on the Desktop ii. scroll down to the disk drives (with horizontal bars illustrating space used) iii. look for XX GB free message for your main hard drive

If you have at least 5GB of space available on your disk, follow Step 2 below (your disk should not have less than 2GB free after installation). If you don't have enough disk space, you can use your current version of Python (3.8, 3.9 or 3.10). You may proceed to Installing PyCharm, below.)

2. Please don't uninstall any version of Python you may have. We will simply configure our tools to use the preferred version.

3. Install Anaconda Python. (Again if you do not have 5GB free on your computer, you can use your current version of Python.)

* Please note that you never need to uninstall any version of Python! Multiple versions can be, and often are, installed on the same system (I currently have four versions installed on my system). If you find that the wrong version of Python is run when you try to use it, you can simply change the 'default' version for your system - I can show you how.

a. Visit

b. Find and click the Free Download link at the top right

c. Click the Download button (which should indicate your OS (Mac or Windows). For Mac, click the small arrow on the right side of the button and choose the correct Mac type

d. The installer will begin to download, usually to your Downloads folder.

e. When complete, find and double-click the installer.

f. Accept all of the prompts and defaults.

g. By default, Anaconda will be installed in a directory located off of your home directory. If you see a warning sign and "You cannot install Anaconda3 in this location", you must install from your home directory.

h. PLEASE NOTE if the Anaconda installer asks for your permission to make changes (requesting a password), please stop installation and start again, making sure to install for "Just Me" or "Me Only". The installer should note that Anaconda will be installed in your home directory.

If it appears that Anaconda is being installed into a directory other than your home directory: when you see the button change install location, please click the button and select your home directory, even if you see an error message similar to "Anaconda cannot install in this location". After selecting your home directory, you should be able to install Anaconda without giving a password.

Note that the installer may invite you to download and install PyCharm; we will do so ourselves in the next section.

i. Installation may take several minutes. When done, the installer will tell you installation is complete.

Installing the PyCharm Editor/IDE

Again, you may use your preferred Editor or IDE (Sublime, IDLE, etc.), but make sure you are comfortable with it. If you already have PyCharm installed, please proceed to "Updating Anaconda and PyCharm".

1. Download and Install PyCharm. (Again, you are free to use the IDE of your choice.)

a. Visit the download page at

b. Immediately beneath Download PyCharm, make sure that your operating system (Windows, macOS or Linux) is selected (it will be highlighted in blue with an underline).

c. Make sure to choose Community Edition on the right side (do not install Professional Edition as it will require a purchase after a trial, and includes features that we do not need). For Mac, make sure the correct .dmg is selected ? if your Mac has an M-series chip, you should select Apple silicon; those with non M-series chips should select Intel. You do not need to provide your email address or sign up with the website, although you may be invited to do so.

d. Download will begin. Keep in mind you do not need to provide your email address or sign up with the website.

e. Once downloaded, doubleclick the downloaded file:

i. On Mac:

a. 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!).

b. 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 and holding down the Cmd+Option keys (so that a swoopy arrow indicating a shortcut is displayed) before releasing on the Desktop. (If you don't see a swoopy arrow, the application itself will be moved to the Desktop, which you do not want - it belongs in the Applications folder.)

ii. On Windows:

a. follow the installer steps and accept all defaults.

b. During the install process you can choose to have a Desktop Shortcut placed on your Desktop. (You will also be able to launch PyCharm using the search or Start > Run... box.) You can also choose to associate .py with PyCharm, but I do not recommend this.

c. Continue to click Next until installation is complete. You may also choose to launch PyCharm for the first time here.

2. Launch PyCharm and respond to initial settings questions. For Mac, find the PyCharm PC icon in Applications and double-click it, or if you placed an icon in the Dock at the bottom of your screen, you can simply click that. For Windows, use the icon you placed on your Desktop or go to the search box and type PyCharm; you should see your program listed as JetBrains PyCharm; click it.

PyCharm may ask a series of questions, for example if you would like to import settings (please do not import any settings), and share usage data with JetBrains to help them improve the product (this is your choice). PyCharm may also ask you to select a Keymap (choose the one appropriate for your platform), a Light or Dark color scheme (recommended choices: "Darcula" or "High Contrast", but you may also select a light color scheme), a launcher script (skip this), and download plugins (skip this). These questions may or may not appear during this step.

Finally, you can click to launch PyCharm.

3. Check out the PyCharm Welcome Screen. This medium-sized box shows the PyCharm PC icon and "Welcome to PyCharm" at the top. This will be the starting point from which we create new projects in PyCharm.

1. Projects on the left is where we can manage projects that we work with. 2. Customize allows us to set color theme and font sizes. However, we will set these as

part of the next step.

4. Set Font Size and Color Scheme. Please keep your font large. Don't strain your eyes!

a. On the left, click Customize.

b. From here you can select a different color scheme (the settings file has set to "High contrast", which I recommend) and an IDE font (I recommend 13).

Updating Anaconda and PyCharm

1. If you already had Anaconda installed, please perform an update:

a. On Mac: search for and open Terminal b. On PC: search for and open Anaconda Prompt

At the command line, execute the first command, and wait for it to complete - you will need to confirm installation (with y) as indicated by the updater.

conda update conda

After this command completes, issue this command:

conda update --all

Again, confirm if needed. You should see messages that indicate success. If you run into any issues, please let me know.

2. If you already had PyCharm installed, please perform an update and remove any custom settings (you may have installed settings if you took Introduction to Python with me):

a. Select PyCharm > check for updates (Mac) or Help > check for updates (Windows)

b. Launch PyCharm and from the welcome screen select File > Manage IDE Settings > Restore Default Settings... and follow the prompt to restore your settings.

Configuring PyCharm Fonts and Colors

Please keep your font large. Don't strain your eyes! If you already have satisfactory PyCharm fonts and colors, you can skip this step.

Launch Settings. At the left of the PyCharm Welcome Screen, choose Customize. Set the Color theme and the Editor Font here.

Downloading Course Files

The python_data_apy.zip file will contain folders with files needed for each week's in-class work and homework. In this step we will download the course zip file, unzip it, and then open it in PyCharm. (Windows users: follow the unzip instructions carefully ? don't double click the file; instead right click the file and choose Extract All.)

1. Download and unzip the python_data_apy.zip file

a. Visit the source data link (this link is at the top of the home page):



b. Click on python_data_apy.zip. The file should download. If you are asked to do something with this file, choose Save and choose to save to your Downloads directory. (Do not double-click the downloaded file.)

If you click on the link and nothing seems to happen, and if you are on Chrome, please right-click the link and choose Save Link As, and then confirm to Chrome that you want to keep the file. (This security warning should not appear, but please let me know if it does.)

c. Find the file you downloaded. Usually, the downloaded file will appear in your Downloads directory, inside your home directory.

i. Most browsers (e.g. Chrome, Edge) will give you the opportunity to go straight to the folder where the file has been saved. After downloading, don't double-click or open the file but look for a flashing or highlighted tab at the bottom of the browser window that lets you choose Show in folder, Show in Finder, Show in Explorer or similar. If you don't see any of this, simply find the Downloads directory inside your home directory.

Firefox will give you the option to save the file. On Mac, this directory is your Downloads directory.

On Windows, Firefox downloads may default to AppData > Local > Temp. For this reason, it's usually a bit more straightforward to use Chrome or Edge than Firefox.

ii. You can also travel to the Downloads directory easily by opening up a Windows Explorer window or Mac Finder window and looking to the left bar for the Downloads shortcut.

iii. Confirm that the file is in Downloads. If you see python_data_apy.zip in the Downloads directory, then your downloaded files can be found here:

C:\Users\username\Downloads (Windows) /Users/username/Downloads (Mac)

Of course username here represents the name of your home directory. Please also record this path for future reference.

(If you used Firefox on Windows, your file may have been downloaded to C:\Users\username\AppData\Local\Temp (where username is the name of your home directory). You can configure Firefox to download to Downloads; you can also simply move the file to Downloads or another folder, or use the default Temp directory. Let me know if you need any assistance with Firefox.)

d. In Downloads: (on Windows, don't double-click the zip file).

i. Windows: don't double-click the zip file. If you do, Windows will open the archive as if it were a folder, but it isn't yet a folder even if it looks like one. (If you did doubleclick the file, just click the "back" arrow at the upper left of the window.)

1) Right click the python_data_apy.zip file, then click Extract All... A dialog showing the full path to the new folder will appear.

2) click Extract. A new window with a folder with the same name will appear in the same directory as the zip file, and Windows will open a new Explorer window displaying the files.

If the above instructions don't work for your system, it may have been configured to open WinZip, 7Zip or an older Windows implementation. In this case, your goal is to have the zip file unzip to a folder called python_data_apy with session_00, session_01 etc., folders. Please let me know of any difficulty with this step.

ii. Mac: double-click the zip file. This will create a folder with the same name as the .zip file.

2. Open the extracted folder as a PyCharm project.

a. If an earlier project is open, close the project with File > Close.

b. Open the project folder. Do one of the following:

a. With the "Welcome to PyCharm" window displayed, drag the unzipped python_data_ipy folder (not the .zip file!) from your filesystem window into the

"Welcome to PyCharm" window. If a Trust and Open dialog appears, click Trust Project. The folder should appear as a folder in the Project window.

b. Or, choose Open and then navigate and highlight the python_data_ipy folder.

c. A "Trust and Open" dialog appears. You may trust this project ;)

d. Look to the file view on the left to see that the project folder is python_data_apy; click the triangle next to this folder to see the session_00_ folder, session_01_ folder, etc.

If for some reason you dragged the wrong folder into the Welcome window, you can always choose File > Close Project and start again.

e. At the extreme bottom right of the PyCharm window, look for Python 3.10, Python 3.9, Python 3.8, or . If you see Python 2.7 or , click it and select the version of Python you installed (usually Python 3.10). If you don't see a selection for Python 3.x, then choose Add New Interpreter > Add Local Interpreter

f. When the project loads and the interpreter is selected, PyCharm will typically take a few minutes to index all the files in the project; this will be expressed as activity at the bottom of the window, including swirly bars and messages. You must wait for this activity to cease before running your Python file.

g. If you see a "download pre-built indexes" you can try it but I have not experimented with this feature.

3. Run a python file.

a. In the project window, expand the session_00_working_files by clicking the tiny triangle next to it. Then, double-click hello_version.py. PyCharm loads the code for this file in the main window on the right side.

b. Double-check the Python version. At the bottom of the PyCharm screen, note the text Python 3.8 or Python 3.9 or Python 3.10. You may also see Python 2.7 or another number starting with 2 or . (If you don't see Python and a number, or at the bottom right, click on View > Appearance > Status Bar from the menu to display the bar that shows the Python version at the bottom right.)

Click on the Python version or , which should raise a popup menu. You should see Python 3.10 next to a green circlet (which indicates Anaconda -- if you did not install Anaconda, you should see this number with a blue and yellow Python icon). If you don't see Python 3.10, chose Add Interpreter... and then follow the directions under Select the Python Interpreter, above. We must be running Python 3 as Python 2 has specific incompatibilities with our version, Python 3.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download