A beginner-friendly way of setting up a Python environment

Marius Safta
Cluj School of AI
Published in
5 min readMar 19, 2019

Hello World,

Python is the most popular language for Machine Learning, with many indispensable libraries. Some have implementations in other languages (Tensorflow in Javascript for example), but Python remains the premier language for AI engineers.

Python is an interpreted programming language, which means it’s executed directly by an interpreter, without the need of compiling, unlike C++ for example. An environment which can interpret the Python code is required in order for scripts to be executed.

Python is available on all operating systems. According to the Jetbrains Python Developers Survey 2018, Linux is the dominating OS, but to start your learning journey, any platform will do.

The question allowed multiple answers by the way, which is why the total adds up to more than 100%

I have found Windows to be absolutely fine when starting :)

Python 2 vs Python 3

There are two main Python versions, with some significant differences, which won’t be covered in this article. While initially Python 3 adoption was rather slow, at the end of 2018 Python 3 was hugely dominant, with 84% of projects.

Python 2 will not be supported past 2020, so we won’t worry about it at all. You might see Python 2 sections in some online courses. These can be safely ignored.

Python Packages

All libraries we’ll be using are distributed via Python packages and must be installed in the environment. This is done easily by using a package manager named PIP, which is included by default in Python versions 3.4 and later. We’ll cover installing packages extensively in the next article.

For now, keep in mind that several libraries are needed, each requiring dependencies, meaning you’ll have a lot of packages being installed and updated. Ideally you shouldn’t have everything in the single Python installation and create all your projects in it. Instead, every project should have its own separate virtual environment in the Python installation with only the necessary packages installed.

This virtual environment management is a best practice and needs to be considered when starting everything up. According to the same Jetbrains Python Developers Survey 2018, 21% of developers still don’t do this.

I realize it can be daunting for beginners and may seem an unnecessary complexity. As a best practice however, it is very positive to do this from the start. Everything can be done via command line, similar to Git let’s say, but it can be more convenient and certainly more beginner friendly to have a more accessible way of doing this. Which brings us to the…

Anaconda Distribution

Considering all of the above, one of the most beginner friendly way to get everything in one package is the cleverly named Anaconda distribution.

In a single installer you get everything needed to start learning:

  • Latest Python version (3.7 at the time of this writing)
  • Jupyter Notebooks which is a web application in which you create documents containing text, code, graphs; it’s an indispensable tool which we’ll cover and use a lot in the future
  • Management of libraries, dependencies, and environments with Conda
  • Spyder which is an IDE (app in which we right code) specifically designed for Data Scientists/ML Engineers
  • VS Code a light code editor from Microsoft available on Mac and Linux as well

It has risen in popularity, 22% of Python developers used Anaconda in 2018, growing by 7% compared to 2017. Windows, Linux and Mac are all supported. You can read more about it and download your preferred installer on the official page.

As a side note, testament to Anaconda’s focus on Data Science/Machine Learning is its inclusion of the R language. R is a significant alternative to Python, especially in Data Science. It was initially the more popular choice, but Python overtook R in Analytics, Data Science or Machine Learning projects in 2017. As well as higher popularity, Python has use cases beyond Data Science or Machine Learning, being used in Web Development, DevOps and Automation. This is an additional benefit of focusing on Python 3.

Installing Anaconda

Anaconda installation is a straightforward affair. As you might expect, Windows and Mac versions have graphical installers. Step-by-step guides are available on the official site for Windows, Mac and Linux.

For Windows my personal recommendation is to check “Add Anaconda to my PATH environment variable” (despite the guide advising otherwise) if you don’t already have or will not create another installation of Python on the same machine.

What this does is it removes the necessity to launch Anaconda Navigator in order to have the Python environment running. This is useful if you decide to use an IDE not directly tied to Anaconda, such as the very popular PyCharm (which is my personal preference).

After installation is complete, open Anaconda Navigator and launch Spyder. It should be installed by default, but if it’s not, install it first from the Navigator…

For a quick test, in the left side type

print(“Hello Python!”)

Press F5 to run the script and save the file if prompted.

In the console, on the right side, you should see Hello Python.

If that is the case, congratulations, your environment is ready!

Conclusion

Hopefully the whole process was not very painful :)

Next time we’ll see how to create new virtual environments in Anaconda or PyCharm and install our first Python packages.

Your opinions, feedback or (constructive) criticism are welcomed in discussions below or at @mariussafta

Join our Facebook and Meetup groups and keep an eye out for discussions and future meetups.

--

--