CHAPTER 7 Python Environment
You are going to learn Python 3. Python 2 has been around for a long time and has a
huge library and module support, but Python 3 is the future language. You can also easily
install Python 3. Consult the download section of the official web site. In any modern
Linux distribution, open your terminal and type “python3”. It will give you the Python
interpreter or shell where you can write your code.
Remember, Python comes with every modern Linux distribution. So you need not
install it anymore. But a few packages you might need to install. There are tons of tutorials
and a lot of community help you can get over the Internet.
In any modern Linux distribution, you need not do anything. Open the terminal and type “python3”, and you will have an output like this:
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
It says my computer has Python 3.4.3. Now you can write some code directly on it to get some output like this:
>>> name = "Sanjib"
In Linux, you save a Python file first. Write this code:
if __name__ == "__main__":
If you are new to Linux, first save this Python file as “hello.py” and then change it to executable with this command:
sudo chmod +x hello.py
On the terminal, run this file with this command:
It will give the output: Hello Python! This is your first Python code. For Windows, download Python installer and document. The document comes in a “.chm” file. It will help later. To install Python, just run the installer. It will be installed in your “C” drive in a minute. Now you can go to “all programs” and run Python from there. Normally, a small IDE called IDLE comes with Python. You can write code and just run it.
you see on the top is IDLE, which is the Python Shell. You can
directly get output from it. You can also go the file section of IDLE and create a new file. I
have done that. I created a file, ”test.py”, and wrote some code in it. Then from IDLE you
can either run this module or just press F5 and it will keep running. As you see in the
picture, our Python code drew a beautiful shape. In Windows 7 or later, you can open
Power Shell and type the same thing and you will get the same result. But I prefer you
install a good Python text editor or IDE first.
For Linux, “Pycharm” community edition is a good choice. It is free. For Windows or
Mac, there are several good free text editors. Search on the Internet and install. The main
advantage is you don’t have to indent every line of code. It is automated. Second, the
support of a large Python library is available in every IDE
What's Your Reaction?