Setup Development Environment – Python

For any programming language having development environment is important. We will start with installing Python using CLI, understand limitations of CLI and then go ahead and setup IDE. We will end with validation of a simple program.

  • Install Python 3
  • Overview of CLI
  • Overview of Pip
  • Limitations of CLI
  • Running Programs using CLI
  • Setup Java and JDK
  • Setup IDE – PyCharm
  • Overview of PyCharm
  • Validate Programs using IDE
  • Setting up Anaconda

Install Python 3

Let us see how we can download, install and validate python.

Setup Python on Windows

Let us go through standard process of installing Python using executables on Windows.

  • Click here to go to Downloads.
  • Make sure to choose 64 bit installer by clicking on Windows (Default one is 32 bit)
  • Choose executable for now
  • Once downloaded complete setup process.
  • Go to Environment Variables and add new entry under path pointing to directory containing Python executables (eg: C:\Users\itversity\AppData\Local\Programs\Python\Python37)
  • Launch python and run print('Hello World')

Setup Python on Mac

We can leverage brew to setup Python on Mac.

  • Command to install python brew install python
  • If we have python already, we can upgrade using brew upgrade python
  • Run python and see if it is launching python 3. If not link using brew link.
  • Launch python and run print('Hello World')

Setup Python on Linux

Let us see how we can setup Python on Linux environment based on the flavor of Linux being used.

  • We have different Linux versions
    • Debian flavors such as Ubuntu
    • RedHat flavors such as CentOS, RedHat, Fedora etc
  • In Debian flavors, we can use apt-get and in RedHat flavors, we can use yum to install or upgrade Python.
  • Command to install python yum install -y python on RedHat flavors.
  • Launch python and run print('Hello World')

Overview of CLI

Let us see some important details about Python CLI.

  • Launching CLI
  • Developing Code using CLI
  • Getting help using CLI
  • Writing code in an interactive fashion

Overview of Pip

Python by itself comes with some core capabilities. However, we need to install plugins to develop applications.

  • Pip used to be additional to be installed. However, starting from 3.4 it is part of Python itself. We can just invoke pip by saying python -m pip
  • Purpose of plugins
    • Interacting with databases
    • Externalize properties
    • Manipulating collections with 3rd party plugins like pandas
    • and many more
  • Managing packages using pip
    • Install
    • Upgrade
    • Remove

Running Programs using CLI

Let us see how we can run programs using IDEs especially by passing run time arguments.

  • We can develop programs using IDE or CLI.
  • Once the program is developed you can save it by using a .py extension. Make sure not to save the program with names such as python.
  • We can then run the program by using python command and passing the program name using a fully qualified path or relative path – python hello_world.
  • To pass run time arguments we need to use sys.argv as part of the code.
    • argv[0] – program name
    • argv[1] – first argument
    • and so on

Limitations of CLI

Let us see some limitation of using CLI and understand the rationale behind using IDE for application development.

  • Taking care of programming conventions such as indentation
  • Readability of the code – Everything (variables, classes, literals etc) will look alike
  • Manageability of the code
  • Integration with 3rd party plugins
  • Integration with tools such as git for code versioning
  • Integration with frameworks such as django, flask etc.

Setup Java and JDK

PyCharm requires JRE. Let us see how we can validate and setup JRE as well as JDK.

On Windows

Let us see how we can setup Java and JDK on Windows.

  • We can validate by launching Command Prompt and then by running java -version and javac -version.
  • If java -version command returns the output pointing to 1.8 that means JRE is already setup. However if javac -version does not work, then either JDK is not installed or Environment Variable Path is not updated.
  • If JDK is installed but environment variable is not updated, then you can skip installing JDK and directly jump to final step to update environment variable. We can validate whether JDK is installed or not by going to C:\Program Files\Java\jdk1.8.0_201
  • It is enough to have JRE, but we will install JDK as it is required for many other purposes (even though not necessarily for learning Python).
  • We can install JDK from this link. JDK includes JRE.
  • Make sure to choose 64bit version for underlying Operating System such as Windows.
  • Validate by launching Cygwin and by running java -version command.
  • Update Environment Variable Path with JDK’s bin. Environment Variables -> System Variables -> Path -> New -> C:\Program Files\Java\jdk1.8.0_201\bin

Setup IDE – PyCharm

Let us go through the instructions to setup IDE and validate by running Hello World Program.

  • Download Pycharm Community Edition from this link.
  • Install PyCharm
  • Develop helloworld Program
    • Create Project – python-demo
    • Create Directory – getting_started
    • Create File –
  • Validate IDE by running Program

Overview of PyCharm

Let us understand some important details of PyCharm.

  • Adding directories and files
  • Configuring Different Versions
  • Installing and Using Plugins
  • Integration with Versioning Tools such as git
  • Refactoring the Code
  • Editing Run Time Configurations while validating programs
  • and many more

Running Programs using IDE

Let us see how we can run programs using IDEs especially by passing run time arguments.

Setting up Anaconda