Installing Python: How to start writing Python code
In this comprehensive beginner’s guide, we’ll look at how to install Python on three major operating systems, choose a Python IDE, and run your code.
Would you like to start coding in Python but don’t know where to begin? Maybe you’ve graduated from an online course like Python Basics and now are looking to continue your Python adventure on your own machine.
But first, why Python?
The answer is simple: Python is a very easy-to-learn and powerful programming language. And that’s why it’s gaining so much popularity among people looking to start programming.
Python doesn’t have complicated syntax or difficult rules. At its core, Python is a practical programming language that’s used in:
- Web development
- Data analysis
- Artificial intelligence
- Natural language processing
- Scientific computing
You can also build lots of different web, desktop, or smartphone apps in Python. With its various modules, Python makes it easy to learn new programming concepts and build increasingly complex applications.
Step-by-step Python installation
Let’s start by installing Python. You can download it for free from the official python website. Python can be installed on:
- Windows
- Mac OS
- Linux
Let’s take a look at how to install it on each of these popular OSes.
Installing Python on Windows
If you’re on Windows, there’s more than one way to install Python. You can download the 32-bit or 64-bit version of Python using a(n):
- Web installer
- Executable (.exe) installer
- Zip file
We’ll download Python 3.7.0 using the executable installer (python-3.7.0-amd64.exe). Why this kind of installer? Because it has flexible user interface and contains all we need to write and run our scripts in Python.
Once you download the installer, run it and follow the steps below.
In the first installation window, we can choose type of installation: Install Now or Customize. If you don’t want to change the installed tools or settings, choose the first option. Also, be sure to check the Add Python 3.7 to PATH box at the bottom of the window to inform your OS where it can find the Python executable so that it may be invoked from the command line.
The installation process starts.
On the last window, click the Close button. You’re done!
In your Start menu, you should see a list of Python 3.7 tools.
Installing Python on Mac OS
Python 2.7 comes pre-installed on macOS, but that’s not the latest version of the language. To take advantage of the latest Python features, you will need to download and install the proper version from the Python website.
Let’s start by heading to the Python downloads page.
Click the yellow “Download Python 3.7.0” button, and you’ll get the latest version of Python for Mac OS.
Open the downloaded file; the Python Installer will show up. Go through the next steps by clicking Continue.
Agree to the licence.
Click Install to start the installation process.
Enter your password when prompted.
The installation will begin and finish shortly.
And that’s it—you’re done! As in Windows, Python 3.7.0 for macOS comes with IDLE already, so just open your Launchpad, find IDLE, and start coding right away! 😃
Installing Python on Linux
We’ll download Python 3.7 on Ubuntu 17.10 (64-bit). There’s no “right” way to do this, but we’ll use the apt-get tool.
Open your terminal and type:
sudo apt-get update
This downloads packages from remote repositories and updates them.
Then, type:
sudo apt-get install python3.7
Once all packages have been installed, type the following command in the terminal:
python3.7
This will launch the Python interpreter, where you can write scripts or perform calculations in real time.
IDLE: a simple Python IDE
Standard Python installations on OSes come with the IDLE Python interactive development environment (IDE). On Linux to install IDLE you type in Terminal:
sudo apt-get idle-python3.7
An IDE provides a user-friendly interface and environment where you can write code; sometimes, IDEs have built-in suggestion support (like the Python extension for Intellisense). Here’s how you launch IDLE:
- Mac and Windows: go to your Python installation folder and select IDLE.
- Linux: type idle-python3.7 in the terminal.
You’ll notice that a shell window appears. Here, you can write your Python code, and you can also run it. To create a new script, simply go to File › New File.
Write your code in this editor, and save it with the .py extension (File → Save As or Ctrl+Shift+S).
Afterwards, you can run the script using the F5 key or by choosing Run → Run Module from the menu.
You will see the result in a shell:
Python tips, extensions, and plugins
The Python IDLE editor is great for beginners, as it doesn’t have any extra features that get in your way. Check out the other options below for more Python IDEs:
- Thonny: An easy and simple IDE created specially for beginners, but with more features. It’s very friendly and contains only the necessary tools. This IDE is available on Mac OS X, Windows, and Linux.
- PyCharm: The most popular Python IDE for beginners and professionals alike. PyCharm integrates tons of libraries and can be extended with plugins. It offers frameworks for web development and scientific computations. This IDE is available for free in the Community edition and paid in the Professional edition. It supports Mac OS X, Windows, and Linux.
- Spyder: (A free, open-source IDE mainly for scientists, engineers, and data analysts. It contains plenty of data science packages for data exploration and visualization. You can install it on Mac OS X, Windows, and Linux.
In any case, you have plenty of options available to choose from for a Python IDE. If you mainly work with Java, for example, then you can install the PyDev IDE for integration with Eclipse. And if you build applications in Visual Studio, you may find the Python Tools for Visual Studio (PTVS) extension worthwhile.
Summary
It’s extremely easy to start programming nowadays with lots of online courses on platforms like Vertabelo Academy, but students often wonder how they can continue programming on their own, outside these sandbox environments. As you can see, the process is really quite simple! All you need is the language of your choice (in this case, Python) and an IDE, and you’re good to go. Happy coding!