Python Labs : Setting up the programming environment

Madhawa Perera
6 min readJan 23, 2019

--

In this article, I will be discussing how to set up an 'easy-to-work' development environment to work with Python.

In Python, there are two major versions as Python 2 and Python 3. If you are a beginner, you may consider learning Python 3 as it’s the future. Yet, having a better understanding of your development environment will help you to switch between these versions and to work with different projects. For an example, if you want to work on a project that uses Python 2 and needs to switch to your other project that uses Python 3 then you need to have a proper understanding how your development environments work. Thus, it is better to have at least a high-level overview of your project environment when you are going to start learning Python.

I have set up my development environment comfortably where I can switch easily and smoothly between my different project setups. In order to do this, you need to have a basic understanding of Python's 'package management' and 'virtual environments'. Don't worry if you do not know what these terms actually mean, I'm discussing them below.

In this article, I'm intended to provide a high-level description to Python package management and virtual environments and then to how to set up your development environment. You don’t have to follow these steps exactly but I myself found this is an easy way of learning/working with Python. Therefore you will certainly find some useful tips and inspirations by reading this article.

Package Management in a nutshell

The first thing you need to know when going to learn about Python is its package management. What is a package and what is the relationship of it to Python? Well, a package is simply a directory, which includes a reusable piece of code (We call them 'modules '— Modules in Python are simply Python files) which can be downloaded from a global registry (a location) into our (developer’s) local environment (to your python project directory). When we write codes we don’t have to write each and every function by ourselves. There are reusable codes out there which are written by other developers and we can incorporate those code into our source codes. Keep in mind that each of these packages may depend on some other packages as well. When you use these packages in your code/program, your code/program depends on those packages. That means in order to run your program you need to have these packages downloaded. Therefore, we call them as dependencies as well. If you are interested in getting to know more about these, refer to my article “What are Python Modules and Packages?” later. However, the scope that will be covered in this article is sufficient for beginners.

Let’s go through a simple example to understand this concept of packages and package management, before moving further.

'Example 01' shown below depicts an instance where I have used a package named ‘numpy’ and its functionality call ‘mean’ to get the mean value of the ‘number_list’. In 'Example 02', the same task is completed without using any packages. Hence, packages include reusable code which minimizes the efforts of developers from writing everything from scratch.

Likewise, depending on your task, you may need to work with lots of different packages. Therefore, to manage these packages you would require tools which we call ‘package managers’. For Python, there are several package managers. I found ‘pip’ and ‘Conda’ to be commonly used ones. When you are creating your developer environment, you have to decide on what package manager to use (There is no restriction as such you have to strict to one package manager).

Virtual environments in a nutshell

The second thing you need to know when going to learn about Python is its virtual environments. The main purpose of the Python virtual environment is to create an isolated environment for Python projects. That means each Python project can have its own Python version, it's own packages/dependencies independently from another project. All these packages are installed within this place called 'virtual environment'. No big deal, these virtual environments are just directories containing a few scripts. For now, hold on to your doubts. This high-level description would be enough to move forward with this article. In order to read further refer to my article on Python Virtual Environments later.

It is important to know, just like there are various tools for Python package management, there are many tools to create these virtual environments as well. I found virtualen, venv, pipenv, Pyenv, Python Environment Wrapper (pew) are to be commonly used ones. If you are using Python 3, then you already have the tool name 'venv'.

As I said before, hold on to all your doubts. Now it’s time to set up your developer environment. If you still don’t understand why we need a package manager, what is a virtual environment, do not worry, moving forward you will get an understanding about why we need to have a package manager, virtual environment and what they actually do.

I thought of using, 'Pip' and 'venv'. But I have seen people use 'Conda' also more commonly. Let's what they are in a nutshell.

‘Pip’ is builtin package manager for Python, whereas 'Conda' is a special package manager which comes with 'Python distribution' called Anaconda (a free and open source distribution of the Python), which includes some additional capabilities. When I say 'Python distribution' it means that Anaconda comes as a bundle of followings.

  • The Python language
  • A plethora of Python packages
  • Spyder and Jupyter (IDEs)
  • ‘Conda’, Anaconda’s own package manager (Conda can be defined as a package and environment manager)

You can read more about 'Conda' here. A key difference between these two package managers is 'Pip' installs 'Python only packages/modules' whereas 'Conda' is capable of installing packages which may contain software written in any language. If you want to distinguish between 'Conda' and 'Pip' more read here. Many prefer Conda to be more feasible and easier to use. Also, using 'Conda' does not mean you cannot use 'Pip', you can use whichever you like inside the 'virtual environment' but not both together. There are various issues when 'Conda' and 'Pip' are used together. My advice is to pick one as your favourite as a beginner.

Next thing is to select an IDE (integrated development environment) to start your development. Again there are several options. Actually many, if you want, but my preferences are PyCharm, Spyder and Jupyter notebook. Please note that I will be using PyCharm hereafter for examples and tutorials.

**Optional — Version Control Systems and Code Repositories

Optionally you can use a good version controlling system such as Git or SVN. Version Controlling Systems (VCS) are used to track changes in source code during your development period. Also, you can save your projects in any online code repositories such as GitHub, GitLab, Bitbucket privately or publicly. Do not worry about this, for now, I'm hoping to write a beginners article to VCS and code repositories. I will update the link here when I'm done with it.

ALright, since we finished deciding on what package manager, which virtual environment tool, which Python version and which IDE to use, the next step is to get hands-on experience.

Prerequisites

Download and install Anaconda. https://www.anaconda.com/download (Make sure you pick the correct OS version and Python 3.7 version prior downloading). This includes everything you need to start with.

If you do not need bulky Anaconda distribution you can download Python 3 directly from here (https://www.python.org/downloads/). ‘Pip’ and 'venv' already comes with Python 3.

Download and install PyCharm Community version. https://www.jetbrains.com/pycharm/download (Again make sure to pick the correct OS version)

These are very easy to install on MacOS. Double-click the downloaded .pkg files and follow the instructions on the popup screens.

P.S. When you go to download Anaconda you will see another distribution call Miniconda. This is a smaller version of Anaconda, and this is ideal if you don’t have disk space for entire Anaconda distribution. As I mentioned earlier, Anaconda comes with Python distribution along with already packed packages where Miniconda contains only Python and Conda.

Please note that these are my preferences to work with PyCharm and Pip and venv. I found this setup to be easier when working with data science-related programming. Yet, you can create your development environment using other tools based on your preferences. Each tool will set up your development environment in a slightly different way.

Well, if you have successfully download Python 3.7 version, and PyCharm community edition you are all set to start your first Python project.

See you in "Python Labs — Say ‘Hi!’ with Python"

If you like this article and the content that I create, you can buy me a virtual coffee ️😊;

Cheers!

--

--

Madhawa Perera
Madhawa Perera

Written by Madhawa Perera

Research Engineer, HCI Researcher, and Sessional Academic at ANU. Passionate about crafting human-centered AI experiences through Mixed Reality (AR/VR)

No responses yet