Python 3 Tutorial : Setting Up Python Development Workspace
Now that we know what is python and where it is used, let’s start developing a few python programs.
In order to start developing programs in python, we need to setup our computer first.
Installing Python :
Python has 2 different stable releases and both of them are significantly different from each other. For the purpose of this tutorial, you need to have Python 3 (3.0 or a later version) installed on your computer.
1. First download the required Python 3 installer for your operating system from http://www.python.org/getit/ . Although Python is already installed on your Mac or Linux PC, you need to download the Python 3 installer and install it because the already installed version will be in 2.x.x. The installer will not replace the shell version of python but instead it will create a new folder for python 3 which you can find in C:/ (on windows machines) and in /usr/local/bin (in Mac and Linux PCs)
2. The Installer will include a full featured command line interface for Python known as IDLE. This application can be used to create and run python programs without any external applications.
3. You can check whether the Python libraries are installed properly using the IDLE application or going to the director where Python is installed and executing the command ‘python’ in a Command Prompt (Windows only).
Installing Python Plugin for Eclipse:
If you’re like me you must be loving the IDE called Eclipse. It’s a full featured IDE for various programming languages and best of all, its free. If you haven’t tried Eclipse yet, you can download the basic Eclipse Classic at http://www.eclipse.org/downloads/.
NOTE : You do not have to install Eclipse for trying out Python Programs. This application is only for who would find an IDE more easier to organize the files. The IDLE application and a simple Text Editor is enough to create and execute all python programs.
In order to get Python Programs working in Eclipse, you need to have PyDev Python Plugin installed in your IDE. Let’s see how to do that :
1. Open up Eclipse.
2. Goto Help > Install New Software.
3. In the Install New Software Dialog Box, Click Add.
4. In the Add Dialog Box, set the Name to ‘PyDev’ and the Location to ‘http://www.pydev.org/updates’ (without quotes).
5. Click OK. After a few minutes, you will be seeing two items on the Install New Software Dialog Box. Check ‘PyDev’ and click Next.
6. Click Next and Follow the Instructions to Install the PyDev Plugin.
7. Now we need to setup the Python3 for the PyDev Plugin and to do that, goto Preferences in Eclipse (Window -> Preferences in Windows and Eclipse -> Preferences in a Mac). Goto Interpreter – Python and Click New.
8. Select the Python3 executable from /usr/local/bin/python3.2 (For Mac) and in C:/python32/python3.exe (For Windows)
9. Once you are done, you will be asked the required libraries. Just Click OK.
10. All the libraries are added. Click OK and You are done.
11. (Optional) You can got General -> Editors -> Text Editors and Check the ‘Show Line Numbers’ if you wish to see Line Numbers in your program.
12. Turn on PyDev Environment by going to the Right Top Corner and clicking on the Squared icon with a Plus sign -> Other -> PyDev.
Time To Test Our Environment :
Now that we have set up the environment for Python Development. Let’s test it whether everything turns out okay.
For IDLE Users :
1. Open Up IDLE.
2. Write a simple print statement :
print (“Hello From Parithi”)
If you could see the output shown on the screenshot, then Congrats! You have written and executed your first Python Program.
If you wish to create python files and execute them,
1. Goto File -> New Window.
2. Save the File with a extension of .py. Example myfile.py.
3. Run the Module by Run -> Run or Press F5. The Output will be displayed in the IDLE Screen.
For Eclipse Users :
1. Create a New Project by File -> Project -> PyDev Project.
2. Click Next and Set the Name for the Project. Set the Grammar Version to 3.0.
3. Click Finish and Right Click on the Project Folder. Click New -> PyDev Module.
4. Type the Program in the Code Editor for test.py :
print (“Hello From Parithi”)
5. Save the File and Click the Green Play Icon on the Top or goto Run -> Run. In the ‘Run as’ Dialog Box -> Select ‘Python Run’ and Click Ok.
6. If everything goes well, you will see the output on the console window :
Congratulations, You have successfully installed and executed your first Python Programs. Now let’s start with the Basics of Python Development