Creating a Pydev python project in Eclipse
How to create a simple Pydev project in Eclipse. You need to have the Pydev plugin installed to do this!
Definitions
- project
- A collection of files and directories that constitute a collection of organized code. In this example our project is called agile.
- package
- library directories in Pydev terms. In this example our "package" is called utilities.system and the package is represented on the file system as a folder called utilities containing a sub folder called system.
- module
- Pydev refers to source files (text files containing code) as "modules". In this example our module is called hello and it contains a very short bit ot test code so we can verify that everything is working.
Objectives
In this example we will create a new project called agile, a package called utilities.system and a single test module called helloRequirements
In order to complete this exercise you will need to have eclipse and the eclipse Pydev plugin installed, running and configured.
Directory Structure
After completing this project you will have a directory structure resembling this:
project_name/package_name/module_name
Real world project directory structure
agile/examples/greetings/standard.py
Creating the Project
(In Eclipse)
File -> New -> Project -> Pydev -> Pydev Project
Project Name: agile
Check your other settings and then choose Finish
. This will take you to the Workbench where you will see your new Pydev project.
Create your Package
Open up your project directory (in this case called agile).
Select the directory called src under the agile
folder.
Right click src and choose New then Python Package
from the menu.
This will open up the Create a new Python package
dialog window.
Leave the Source Folder options as is (/agile/srv)
Name your new package "utilities.system" (with no quotes!)
Choose the "Finish" button.
This will create a nested structure as follows:
agile
src
utilities
system
The cursor will be on the file __ini__.py in the folder called system:
agile\src\utilities\system\__ini__.py <<- you are here!
Create your module
Now we will create a file with some code in it in the folder. called system If you have not made any changes since the last step you should be able to:
Right click on the folder called system and then,
Choose New, Pydev Module
This will open the "Create a new Python module" dialog.
Module Name = hello
Check you other settings in the dialog and then choose:
Finish
Testing with some Python code
After choosing "Finish" Eclipse will open the newly created module (file) called hello.py in the Eclipse editor. This file, called a module in Python terminology, will contain a small bit of code (a comment or docsting) indicating the creation date and the user id of the individuals who authored the code.
Pasting in some test code
You may add the following code by pasting it below the modules doc string (the doc string is all the text contained in the space delimited by the three single quotes near the top of the file):
print "Welcome to Eclipse, Pydev and Python!"
Running your test code
You can run your code in a few ways.
Using shortcuts / hotkey
CTRL+F11
Some host systems will allow you to use the Ctrl+F11 combination( then you would choose the option "Python Run", then OK, ), then you will be prompted to save your code, choose "OK" again after checking the directory (should be agile\src\utilities\system\...
Using in context menu
Right click in your module and choose Run As -> Python Run
Program Output
To see your programs output look at the Consoleview (normally in the lower center half of the Eclipse window). You should see something like this:
Welcome to Eclipse, Pydev and Python!

