Introduction to Python Getting Started with Python and the PyCharm ...

Introduction to Python

Getting Started with Python and the PyCharm Editor/IDE

Goals for Getting Started:

? Install the Python interpreter for running programs ? Install the PyCharm text editor/IDE for writing programs ? Download and install the custom PyCharm settings file for this course

Before our first class, you should complete these instructions, as well as those in the "Writing, Running and Debugging Programs" document.

Sometimes it seems more efficient to "skim" long instructions and skip ahead on your own; please don't do that here. Instead, read and patiently follow these instructions to the letter, and let me know if you encounter any problems or if you have questions.

Keep in mind that any divergence from these instructions can create problems now, or later in the course. One of the first lessons that I can offer to you is the necessity for attention to detail in this environment.

(If you already know how to write and run Python programs, you may not need the instructions that pertain to the PyCharm text editor/IDE. However, you may find it to be a helpful tool. PyCharm is well regarded in the industry. I will be using PyCharm for most class demonstrations, including the use of its valuable debugger.)

If you decide to use another IDE (such as VSCode) for this class, you must inform me as soon as possible, as there may be issues in regards to the use of paths to access class resources. In addition, you'll be "on your own" regarding using the program. I do not recommend using an IDE you are not already familiar with.

These instructions should work on any standard computer (Windows, Mac or Linux). If you are hoping to do your classwork on a Chromebook, iPad or other nonstandard computer, this may be possible, but I do not have any specific instructions. Let me know if this is the case for you.

Writing and running programs

There are two components needed for writing and running programs:

1. the python interpreter (a program for reading your Python statements and converting them into machine instructions)

2. a text editor or IDE (Integrated Development Environment, basically a text editor that understands that you are writing code, and can send the code to the interpreter for execution).

Installing the Python Interpreter from Miniconda

I recommend Miniconda Python: ? a popular distribution of Python ? includes the Python interpreter ? makes it easy to install additional modules maintained by Anaconda (module installs can sometimes destabilize your python system because of version mismatches; installing Miniconda from Anaconda can minimize the possibility) ? requires a small amount of space on your hard drive

1. Install Miniconda Python from Anaconda. In this step, Python 3 will be installed onto your Mac or Windows computer. (If for some reason you don't want to install Miniconda, you can install the Standard Distribution of Python -- see the separate document Install Python from . When done, return to Installing PyCharm, below.)

* 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 we find that the wrong version of Python is run when you try to use it, we will simply change the 'default' version for your system.

a. Visit . Scroll down to see a series of links appearing under "Latest Miniconda installer links".

b. Windows: download by clicking on Miniconda3 Windows 64-bit Mac: choose Miniconda3 macOS Intel x86 64-bit pkg (for older, Intel-based Macs) or Miniconda3 macOS Apple M1 64-bit pkg (for newer, "M" series Macs)) (If you're not sure which type of Mac you have, click on the Apple icon, choose "About This Mac" and look at "Processor" ? you'll see "Intel" or "M1", "M2" or "M3")

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

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

e. Accept all of the prompts and defaults, until you see the button labeled `Change Install Location...' near the bottom of the installer. Do not click this button.

f. Please confirm that the installer is indicating a "standard installation of this software in your home folder".

g. PLEASE NOTE if the Miniconda 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 Miniconda will be installed in your home directory.

If it appears that Miniconda 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 "Miniconda cannot install in this location". After selecting your home directory, you should be able to install Miniconda 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.

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

Setting your PATH Environment Variable to Point to Python

The PATH environment variable is a special value used by your operating system (Windows, Mac or Linux) that helps the os (your computer's operating system) find programs on your system. As python is a program just like any other, we must tell the os where to find it.

1. Test whether the PATH environment variable has been correctly set.

Your path may be already set, or it may need to be set -- we'll find out which, here.

a. Windows: use the Windows search blank (usually at the bottom left of your Windows screen) to search for and open a new "Command Prompt" window.

At the prompt in the newly opened window, type where python. If you see the path C:\Users\[homedir]\miniconda3\python.exe (where [homedir] is the name of your home directory), then your path is correctly set. You can skip to "Installing the PyCharm Editor\IDE" below. If not, please proceed to the next numbered step.

Or if you do see the miniconda3 path but it is not the first path listed, please proceed to "Set the PATH Environment Variable" below.

b. Mac: use the Spotlight search (the magnifying glass at the top right of your Mac screen) to search for an open a Terminal window. Make sure this is a new window, not an existing one!

At the prompt in the newly opened window, type which python. If you see the path /Users/[homedir]/miniconda3/bin/python (or /python3) (where [homedir] is the name of your home directory), then your path is correctly set. You can skip to "Installing the PyCharm Editor\IDE" below. If not, please proceed to the next numbered step.

c. Again, if you do not see the miniconda3 path, then you must set the PATH environment variable to point to Python, as shown below. If you have already done that step and it still doesn't show (and show first in the case of multiple paths), please get in touch with me right away.

2. Verify the install path for miniconda.

This is only needed if your version of Python did not show up in the previous step.

a. Open a Windows Explorer or Mac Finder window (i.e., the window that shows your files and folders). Make sure you are looking at your system's home directory (usually the first directory displayed when you open a new window). In most cases you should see a little house icon highlighted at the left of the window. (Some systems default to the Desktop or Documents directory -- make sure you're looking at the home directory.)

b. Look for a folder called miniconda3.

c. If you see this folder, then your correct path is one of the following (where [homedir] is the name of your home directory):

Mac:

/Users/[homedir]/miniconda3/bin

Windows:

C:\Users\[homedir]\miniconda3

d. If you do not see miniconda3 in your home directory and you are sure you have run the miniconda installer, please get in touch with me.

Please note that a general search for the term `miniconda' may not show you the correct path to use. Our goal is to see if a miniconda3 folder is in our home directory. You must find and look into your home folder for miniconda3. If you do a separate general search for it, you may find other files with that name -- this could mislead you into thinking it's in a place other than it is -- it is supposed to be miniconda3 in your home directory. Again, if it isn't, please get in touch right away.

3. Set the PATH environment variable.

This step is needed only if your version of Python did not show up in the "Test the PATH environment variable" step.

a. Windows: follow the directions found at this link: The goal is to add the path indicated above (your path to python, which should be the path to the miniconda3 folder you found at C:\Users\[homedir]\miniconda3) to the first path in the PATH variable (so your system can find this version of python). Make sure to replace [homedir] with the name of your home directory.

After doing this, please close any open Command Prompt windows (only a newly opened window will see this change) and return to the previous step ("Test the PATH environment variable") and test as described.

b. Mac:

i. Use the spotlight search (the magnifying glass at the top of the screen) to search for Terminal, and select it, or you may use the existing Terminal window you opened earlier.

ii. In the opened terminal window, click right after the prompt and type cd, then hit [Enter].

iii. If your Terminal prompt ends in a % sign, type touch .zshrc and hit [Enter]. If the prompt ends in a $ sign, type touch .bash_profile and hit [Enter].

iv. Again at the prompt, type open .zshrc or open .bash_profile, choosing the filename that you touched above. Your mac's default text editor should open.

v. If the file is not empty, scroll all the way to the bottom of the file.

vi. Type the following in the file:

export PATH=/Users/[homedir]/miniconda3/bin:$PATH

[homedir] represents the name of your home directory. This tells your system to look in that first directory when attempting to execute the command python.

vii. Save the file and close out the editor. Make sure to close out your existing terminal window as only new windows will see the change.

After doing this, please return to the top of this step ("Test whether the PATH environment variable has been set") and test that the PATH environment variable has been set.

Installing the PyCharm Editor/IDE

Special Notes on Text Editor / IDEs:

? if you have PyCharm already installed, you can skip this section on installing, but we will also make sure that PyCharm is using Miniconda as its Python version

? if you prefer to use another IDE or text editor (such as VSCode, IDLE, Sublime, Eclipse, etc.) you may do so, but I strongly recommend that you proceed only if you're familiar with using this tool to perform the following: writing and running Python programs; and inputting text at the keyboard with the input() function. If you're not sure about any of these items and still want to use a different IDE, please contact me.

? please do not expect to use Jupyter notebook as your main text editor / IDE. We may make some use of Jupyter for in-class exercises and tests only. Jupyter is not appropriate for project work!

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

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

Google Online Preview   Download