System Setup for Python, PyDev and Eclipse



Follow these steps to set up your Eclipse development environment for developing Python programs. You should do this only when you have enough time to reasonably wait for all the downloads and installations to complete.

Contents/Steps:

    Installing the Python 3.2/3.3 Interpreter
    Installing the Eclipse IDE
    Initializing your Eclipse Workspace
    Installing the PyDev Python Development Plugin for Eclipse
    Configuring PyDev and Eclipse to work Python 3
    Saving Orphan .pyc Files: Critical PyDev Configuration Step
    Validating Installation of Python 3 and PyDev under Eclipse
    Running the PyDev debugger and Python 3 under Eclipse

Install Python 3.2/3.3

This quarter's project only works with Python version 3.2 and 3.3. If you have installed a newer version, you must additionally get Python 3.2 or 3.3 and make sure to use it for anything project related. If you do not follow this warning, you will get errors when you run the project complaining about a "bad magic number". If you have not already installed Python 3.2 on your machine, http://python.org/download/releases/3.2.3/ is the installation site.
Install Eclipse

You should use the Eclipse development environment for all your programming in the course. Eclipse provides a superior environment to IDLE and has a debugger, PyDev, that you will learn.
Windows

    http://www.eclipse.org/downloads/ is the download site; please choose the classic edition.
    Eclipse downloads as a zip file. Install either the 32 or 64 bit version.
    Unpack the zip file into C:\Program Files\eclipse.
    Create a desktop shortcut to the application program, which should be C:\Program Files\eclipse\eclipse.exe

Macintosh

    http://www.eclipse.org/downloads/ is the download site; please choose the 'classic' edition.
    Eclipse downloads as a tarred gnu zip file. Install either the (Cocoa) 32 or 64 bit version.
    Unpack the zip file into your Applications folder, which creates and populates /Applications/eclipse.
    Create an application shortcut by dragging /Applications/eclipse/Eclipse.app to your dock.

Set Up Eclipse Workspace

When you start Eclipse, it asks where you want to put your workspace. The workspace is the top level folder where all your projects will reside. Use the default workspace directory if at all possible.
Note: If you are using your CS Department account and CS Department machines, you will have to put your workspace into your CS account directory. The location of your CS account is the H: drive; navigate there and create your workspace.
Windows Default Location: (for your own machine)
C:\Documents and Settings\your-username\workspace
Mac Default Location:
/Users/your-username/Documents/workspace
Steps:

    Start Eclipse.
    Select the checkbox Use this as the default and do not ask again.
    Select "Workbench" if you are presented with a window of large icons. The Workbench icon/button should be in the upper right of the window.

Installing the PyDev Python Development Plugin for Eclipse

PyDev is an Eclipse plug-in for developing Python projects. If you do not have installation privileges on your machine, you may install PyDev in your workspace.
Within Eclipse, follow these steps:

    Navigate to: Help->Install New Software...
    Click the "Add" button to view a pop-up window dialog.
    In "Name" enter: PyDev
    In "Location" enter: http://pydev.org/updates
    Click the "OK" button and the window presents information on PyDev.
    Select the checkbox next to "PyDev" and click the "Next" button.
    Re-select the "PyDev" entry and click the "Next" button.
    Select "Next", accept license agreement and click the "Finish" button.
    Now you are going to accept the certificate. One of these windows will bring up a checkbox that you *must* check in order to correctly accept the certificate.
    If prompted, trust all certificates.
    Quit and restart Eclipse (It usually tells you a restart is necessary).

Configuring PyDev and Eclipse to work with Python 3

This part of the setup instructions describes how to configure Eclipse's PyDev environment to work with Python 3.
Windows PyDev Configuration

    In Eclipse, go to: Window->Preferences.
    Go to: Pydev->Interpreter - Python.
    Click the "New..." button.
    In "Interpreter Name" enter: python3
    In "Interpreter Executable" click the "Browse" button and navigate to C:\Python33\python.exe. Click "Open" with python.exe highlighted.
    (Note: This path may be different if you are using a different version of Python 3 or a different installation location.)
    Click the "Ok" button two times.
    Click the "Apply" button. Python 3 now should be configured.
    Click "OK" to return to main window.

Mac PyDev Configuration
This is for mac owners, not the CS department machines. Read ahead to find the information for setting up your account on the CS department Mac machines.

    Go to: Eclipse->Preferences (see diagram below).
    Go to: Pydev->Interpreter - Python.
    Click the "New..." button.
    In "Interpreter Name" enter: python3
    In "Interpreter Executable" click the "Browse" button and navigate to /Library/Frameworks/Python.framework/Versions/3.3/bin/python3. Click "Open" with python3 highlighted.
    (Note: This path may be different if you are using a different version of Python 3 or a different installation location.)
    Click the "Ok" button two times.
    Click the "Apply" button. Python 3 now should be configured.

Saving Orphan .pyc Files: Critical PyDev Configuration Step

By default, PyDev will always delete .pyc files when you build or run your program. The project contains many .pyc files that have no associated, .py source. To preserve these .pyc files, you must change your settings before you run the project the first time. Otherwise, PyDev will delete the .pyc files, and the project will not run.

    In the top menu, go to preferences (on a Mac, it is under the Eclipse pulldown, and on Windows, it is under the Window pulldown). Go to: Preferences->PyDev->Builders
    In the lower part of the window, change the option for "How to handle .pyc/$py.class deletion" to "Only delete .pyc when .py delete is detected."
    Click the Apply button.
    Below is an image of the settings screen.

CS Department Ubuntu Linux Configuration
Note: If you use the CS Department's Ubuntu Linux lab machines, you must set up your CS account using the same configuration operations described earlier in "Configuring PyDev and Eclipse to work Python 3". However, instead of the typical locations, use the program locations below for the relevant interpreter program executables.
Program Locations for Lab machines running Ubuntu Linux (ICL1-ICL3):
The locations for the ubuntu machines in the CS Department are below. Eclipse is the Helios edition, and Python3.2 is the interpreter available; the 'mu' suffix below is for a multi-user installation.

    Ubuntu Eclipse location: /usr/local/dcs/versions/eclipse-3.6/eclipse
    Ubuntu Python 3.2 location: /usr/bin/python3.2mu

CS Department Macintosh Lab Machine Configuration
Note: If you use the CS Department's Macintosh lab machines, you must set up your CS account using the same configuration operations described earlier in "Configuring PyDev and Eclipse to work Python 3". However, instead of the typical locations, use the program locations below for the relevant interpreter program executables.
Note: You must use these 32-bit versions of Python.
Program Locations for CS Macintosh Lab machines (ICL5, graduate lab):

    CS Dept. Mac Eclipse: /Applications/Eclipse (this may be 3.6 or 3.7.)
    CS Dept. Mac Python 3.2: /usr/local/bin/python3

Validating Installation of Python 3 and PyDev under Eclipse

To validate, you create a PyDev project that uses Python 3.2. Here are example steps for Python 3.1:

    Go to: File->New->Pydev Project
    In "Project name" enter: PyTest3
    For "Grammar Version" select: 3.0
    For "Interpreter" select: python3
    Unselect the checkbox for "Create default src folder...".
    Click the "Finish" button. Your workspace shows up as a folder named "PyTest3.1" in the Navigation view.
    Select "+" next to your "PyTest3" folder to display its contents. For now you should only see the interpreter.
    Right click on "PyTest3" folder and select New->File.
    In "File name" enter: print3.py
    Click the "Finish button". This creates your python file print3.py that you see in the Code view window.
    Enter print( "Hello Python 3." ) into the file editor.
    Select File->Save All. The asterisk next to print3_1 in the tab for the code window should disappear, indicating the file is saved.
    Right click on print3.py in the Navigation window and select: Run As -> Python Run.
    The "Hello Python 3." text string should appear in the Console window.
    If there are any errors they will be highlighted here. You can click on individual errors to be brought to the line of code in the Code view window.
    Your actual program file, print3.py, is in a directory named PyTest3 under your workspace folder.

Validating the PyDev Debugger under Eclipse

To validate the debugger for Python 3, open your PyTest3 project.

    Open the print3.py file.
    Double-click in the margin next to the line print "Hello Python 3.". A PyDev breakpoint 'dot' icon should appear next to the line.
    Right-click on the file name in the Navigator, and select Debug As -> Python Run.
    Click "Yes" in the "Perspective Switch" dialog, and Eclipse will change its view to the PyDev perspective.
    You should see the cursor next to the line; the debugger has begun running the program and stopped at the break point.
    In the Run menu, choose "Step Over" to execute the statement. If there are subsequent statements to execute, PyDev stops at the next statement. Since this is the only statement, the program terminates.
    (To remove the breakpoint, double-click again on the breakpoint doc icon.)

Comments

Popular posts from this blog

Live Server, Ekstensi Visual Studio Code untuk Front End Developer

Visual Studio Code, Text Editor Pilihan Saya

Laravel Tutorial: Install Framework Laravel