Python Environment Setup

In this lesson, you’ll learn how to get Python on your computer by setup up a Python development environment and how to run it.


What is an environment setup?

Environment setup is a combination of hardware and software to execute the programs. It includes setting up the hardware, the operating system, the software, the test terminals, and other tools needed to run the test.


Python environment setup

Python is accessible on many operating systems, including Linux and Mac OS X. To get started, You must follow a few steps to set up the Local Environment Setup.

  • Installing Python on your machine
    Python installation for Windows
    Python installation for UNIX and Linux
    Python installation for Mac
  • Setting up PATH
  • Running Python with:
    Interactive Interpreter
    IDE supports Python

Installing Python on your machine

Get a copy of the standard distribution of the Python program from https://www.python.org/downloads based on your operating system, hardware configuration, and local machine version. Let’s examine the basic steps for installing Python on different machines.


Python installation for Windows

Here’s how to install Python on a Windows computer.

  • Go to https://www.python.org/downloads/ in your web browser.
  • Follow the link to the python-XYZ.msi file for Windows, where XYZ is the version you want to install.
  • To use the python installer, python-XYZ.msi and Microsoft Installer 2.0 must be supported by Windows. To check if your computer supports MSI, save the installation file to your local drive and run it from there.
  • Run the file you downloaded, which uses the easy-to-use Python install wizard. Just use the default settings and wait for the installation to finish.

Python installation for UNIX and Linux

Here are the following procedures to install Python on a Linux or UNIX system.
Go to https://www.python.org/downloads/ in your web browser. Follow the link to download the Unix/Linux source code that has been zipped.

  • Download and unzip files.
  • Edit the Modules/Setup file if you want to change some settings.
  • run ./configure script

  make

 make install

  • All the above steps put Python in the standard location /usr/local/bin and its libraries in /usr/local/lib/python, where XX is the version of Python.

Python installation for Macs

Here are the following procedures to install Python on a Mac.

Python is already on most new Macs, but it may not be up to date for a few years. See https://www.python.org/download/mac/ for instructions on how to get the latest version and other tools to help with development on a Mac. MacPython can be used on Mac OS versions before Mac OS X 10.3, which came out in 2003.

It is kept up to date by Jack Jansen, and you can find all the documentation on his website at https://www.cwi.nl/jack/macpython.html. You can find all the information you need to install Mac OS.


Setting up PATH

Operating systems feature a search path that instructs the OS to seek executable files since programs and executable files can be in numerous directories. The path is kept in an environment variable, a named string that the operating system keeps track of. This variable holds information that other programs and the command shell can use.

In Unix, the path variable is called PATH, and in Windows, it is called Path (Unix is case-sensitive; Windows is not). In Mac OS, the path is Programs, and other executable files can be in many directories, so operating systems have a search path taken care of by the installer. You must add the Python directory to your path to use the Python interpreter from any directory.


Steps to Setting up PATH in Unix or Linux

To add Python’s directory to the path for a specific Unix session.

  • Type setenv PATH “$PATH:/usr/local/bin/python” in the csh shell and press Enter.
  • In the Linux bash shell, type export PATH=”$PATH:/usr/local/bin/python” and press Enter.
  • Type PATH=” $PATH:/usr/local/bin/python” into the sh or Ksh shell and press Enter.
  • The path to the Python directory is /usr/local/bin/python.

Steps to Setting up PATH in Windows

To add the Python directory to the path for a specific Windows session, do one of the following:

  • Type path%path%;C:Python and press the Enter key at the command prompt.
  • Note − C:\ The path of the Python directory is Python.

Running Python

You can start Python in three different ways.

  • Run Python Script from the Interactive Translator
  • Run Python Script from the Command-line
  • Run Python Script from the IDE

Run Python Script from the Interactive Translator

You can start Python from Unix, DOS, or any other system with a command-line interpreter or shell window. In the interactive interpreter, you can start writing code right away.

$python # Unix/Linux

or

python% # Unix/Linux

or

C:> python # Windows/DOS

Run Python Script from the Command-line

You can run a Python script from the command line by calling the interpreter on your application like this:

$python script.py # Unix/Linux

or

python% script.py # Unix/Linux

or

C:>python script.py # Windows/DOS

Run Python Script from the IDE

A code editor is a tool for writing and changing code, and they are usually easy to carry and can help you learn. You can also run Python in a Graphical User Interface (GUI) environment if your system has a GUI program that supports Python. However, you’ll need to test and optimize your code as your application matures, and that’s where Python-integrated development environments (IDEs) come in.


What are IDEs?

IDEs make programmers more productive by adding the ability to edit source code, build executables, and find bugs.

The problem with IDEs is that they can be hard to use. A text editor doesn’t understand your code better than an IDE (Integrated Development Environment). IDE usually has automated build, code indentation, testing, and debugging, which can help you get your work done much faster. Below, famous IDE for Unix, Linux, Windows, and Mac are given.

  • Unix: IDLE is the first IDE for Python on Unix.
  • Windows: PyCharm is a great Python IDE for Windows. It is an IDE with a Graphical User Interface (GUI).
  • Macintosh: The Macintosh version of Python and the IDLE IDE can be downloaded as MacBinary or BinHex files from the main site.

What makes up an IDE

Let’s look at a few of the most essential parts of an IDE:

1. Emphasis on syntax

If your IDE knows the syntax of your language, it can give you visual cues and keywords that make the syntax easier to read.

2. Autocomplete IDEs

IDEs are usually very good at guessing what you will type next, which makes coding much faster and easier.

3. Building Executables IDE

IDE handles interpreting the Python code, running Python scripts, building executables, and debugging the applications.

4. Debugging

IDEs have debugging tools that make it easy for programmers to find mistakes in their code when a program doesn’t run right.


Top Python IDEs

We’ll look at a few of the most well-known Python IDEs now that you understand an IDE. Note that we won’t rank these IDEs just for fun because we think that different IDEs are made for different features.

  1. Pydev.
  2. Pycharm.
  3. Sublime Text.­
  4. Visual Studio Code.
  5. Vim.
  6. GNU/Emacs.
  7. Atom/Atom-IDE.
  8. IDLE.

Ensure the Python environment is set up correctly and running well. Many websites have already set up a Python programming environment online, so you can try out all the examples while learning the theory. You are welcome to change any example and use it online.