0% found this document useful (0 votes)
10 views

Introduction To Anaconda and Python Installation and Setup

Uploaded by

king
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Introduction To Anaconda and Python Installation and Setup

Uploaded by

king
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

¦ 2020 Vol. 16 no.

Python for Research in Psychology

Introduction to Anaconda and Python:


Installation and setup

Damien Rolon-Mérette a B , Matt Ross a , Thaddé Rolon-Mérette a & Kinsey Church a


a
University of Ottawa

Abstract Python has become one of the most popular programming languages for research in the Acting Editor
past decade. Its free, open-source nature and vast online community are some of the reasons be- Nareg Berberian
(University of Ot-
hind its success. Countless examples of increased research productivity due to Python can be found
tawa)
across a plethora of domains online, including data science, artificial intelligence and scientific re-
search. This tutorial’s goal is to help users get started with Python through the installation and setup Reviewers
Tarique Siragy (Uni-
of the Anaconda software. The goal is to set users on the path toward using the Python language by versity of Ottawa)
preparing them to write their first script. This tutorial is divided in the following fashion: a small
introduction to Python, how to download the Anaconda software, the different content that comes
with the installation, and a simple example related to implementing a Python script.
Keywords Python, Psychology, Installation guide, Anaconda. Tools Python, Anaconda.

B [email protected]

10.20982/tqmp.16.5.S003

mon problems, video tutorials, and much more. These re-


Introduction
sources are often free to access and cover the most com-
Why learn Python? Python is an object-oriented, inter- mon problems developers run into at all levels of difficulty.
preted, mid-level programming language that is easy to In addition to the benefitial features mentioned above,
learn and use while being versatile enough to tackle a vari- Python has many different qualities specifically tailored
ety of tasks (Helmus & Collis, 2016). It’s open-source nature for the field of psychology (Dalmaijer, 2016). It can be em-
has skyrocketed its popularity since its first appearance in ployed at every step of the research procedure, from au-
1991 (Van Rossum & Drake Jr, 1995), and is now considered tomation to analysis. For example, in the field of clinical
among the top programming languages to learn (Saabith, psychology and clinical neuroscience, Python is being used
Fareez, & Vinothraj, 2019). to build sophisticated machine learning algorithms to in-
It is free to use, has cross-platform compatibility (Mac, terpret the onset of development, maintenance, and/or re-
Windows, Linux, Ubuntu) and has low system require- mission of psychopathology based on personal characteris-
ments, giving any individual the opportunity to code in tics and sociocultural contexts (Coutanche & Hallion, 2019).
Python. It already has an immense community ranging In the field of neuroscience, NeuroRA (neural represen-
from everyday individuals to top research scientists who tational analysis; an easy-to-use Python toolbox for com-
have developed interesting projects related to data science, prehensive representation analysis) is being used for con-
machine learning, artificial intelligence, app and game de- ducting powerful cross-modal data analyses for various
velopment, scientific research and more. These projects types of neural data (e.g. EEG, MEG, fNIRS, fMRI; Lu & Ku,
are easy to find thanks to the open-source community that 2020). In developmental psychology, Python’s natural lan-
continues to develop the language capabilities and can be guage processing capabilities are being used to automate
searched by simply adding the key word “Python” to any and analyze interviews (Underwood, Kirchhoff, Warwick,
inquiry. This community also provides a wealth of re- & Gartstein, 2020). Finally, for data capturing, Python is be-
sources such as courses, source codes, solutions to com- ing used to facilitate the creation of specific experimental

The Quantitative Methods for Psychology


2 S3
¦ 2020 Vol. 16 no. 5

Figure 1 Available Anaconda distribution installation packages across platforms and processor type.

paradigms and record participant’s answers accordingly and Pages for writing text, but in truth they are so much
(PsychoPy; Knorr, Marxen, & Petzold, 2019). These are just more. IDEs contain many useful features to write, edit
a few examples of how Python can be used in psychology and debug code, visualize and inspect data, store variables,
to speed up research at every step and how it can allow for present results, and collaborate on projects. While the dis-
more powerful analyses and research models. play and the quirks of an IDE differ, the programming lan-
So why learn Python? It can save you time, increase guage does not. Thus, changing IDEs in Anaconda does not
control over your experiments, allow your imagination to result in drastically changing your Python code. The learn-
be the limit of your research designs and because it can ing curve is mostly related to understanding Python’s syn-
optimize your research productivity. With such objectives tax. Once you learn how to code in one IDE, you will be
in mind, this tutorial was designed to get you started as able to transfer this skill to another with ease. One IDE
fast as possible by explaining how to install the most op- is not necessarily better than another, each comes with its
timal packages with the Anaconda distribution tool kit. own pros and cons and which one you choose comes down
We cover how to use these packages, important terminol- to personal preference.
ogy, how to employ various Python interfaces, and how to Downloading the toolkit also provides you with an
implement your first few lines of code, effectively build- enormous selection of prebuilt functions that the Python
ing your first program and preparing you for the next few community has coded in the past. These functions are re-
steps in learning Python. grouped in what are called libraries and can be down-
loaded easily through Anaconda. There are many different
Anaconda
ways to install and use Python on your computer, but Ana-
What is Anaconda? Anaconda is a free software that pro- conda is a simple, well-supported, graphical user inter-
vides you with a toolkit that is tailored for research and face (GUI) that includes the most important libraries and
science. Installing Anaconda gives you access to different IDEs in its installation. Anaconda also simplifies the pro-
environments that allow you to code in either Python or cess of keeping all of these libraries up to date. Thus, rather
R. These environments, also known as integrated devel- than installing Python separately with different IDEs, li-
opment environments (IDEs), are platforms or apps that braries and functionalities, Anaconda can do it for you in
greatly ease the development of code. They serve a simi- one installation.
lar role to text processors like Microsoft Word, Google Doc As mentioned on their website, Anaconda is “the eas-

The Quantitative Methods for Psychology


2 S4
¦ 2020 Vol. 16 no. 5

iest way to perform Python/R data science and machine


Jupyter Notebook and JupyterLab
learning on a single machine. Developed for solo practi-
tioners, it is the toolkit that equips you to work with thou- Jupyter Notebook is a web-based IDE that uses your de-
sands of open-source packages and libraries.” It is a great fault web browser. Each block of code can be run sep-
platform for beginners, as well as advanced programmers, arately, making it highly flexible and easy to experiment
to tackle different projects and is the best approach to get- with. This allows for different types of texts to be used
ting started with Python. in the same Notebook. Thus, code outputs, visualizations,
equations, and normal text can be used all in one place.
Downloading and Installing Anaconda
This makes it effective to create and share documents and
The Anaconda website provides the necessary links to to present your code and results in an organised and aes-
download the software for free in either Windows, Mac, thetically pleasing way. Since it is web-based, it also makes
or Linux. It also has starter videos, documentation, train- it easy to share Notebooks with others and is optimal for
ing, and support. To simplify this process, this tutorial has collaborations. JupyterLab is an extension of the Jupyter
provided a step-by-step installation guide as well as a sum- Notebook with many more features. In JupyterLab, Jupyter
mary of the different options you may encounter. Notebooks are integrated with other applications, like a
To download and install Anaconda, you must first se- command-line Terminal, a code Console and a Text Ed-
lect your operating system, desired version of Python, itor. As interesting as JupyterLab is, we recommend be-
and whether you want 32-Bit or 64-Bit Graphical Installer ginning with Jupyter Notebook as it is easier to use and
which depends on your system’s processor type (see Fig.1) contains the fundamental tools to learn Python program-
and click on the appropriate link from their website to be- ming and conduct data analysis. Jupyter Notebook will
gin the download: Official Anaconda Website for Down- be the go-to IDE for this tutorial. For more information
loads. about Jupyter Notebook and JupyterLab, see the Jupyter
It is important to notice that Python 3 is the latest ver- web page at jupyter.org
sion and is being constantly updated and supported. The
Spyder
previous version, Python 2 is still offered, but is no longer
being maintained. Consequently, this tutorial will focus on Spyder is a highly functional IDE specifically designed for
Python 3. data analysis. It can be seen as an all-in-one IDE, contain-
Once the download has finished, open the Anaconda ing an editor to write code scripts, a variable explorer to
setup. If you are using a Windows operating system please easily inspect data, an Ipython console and much more. It
follow Fig. 2 and if you are using a Mac operating sys- also includes powerful tools for code inspection and debug-
tem follow Fig. 3. For the Windows installation in the ging, allowing the user to analyze code either entirely or
“Advanced installation options” (Fig. 2, panel e) , we rec- line-by-line to detect and fix errors. The interface is also
ommend not selecting either option for first time users. highly customizable, allowing you to choose things like the
We encourage anyone interested in using these options to arrangement of the different panes and even the layout
do their research to ensure they understand the pros and colour (we recommend Spyder Dark). For more informa-
cons. tion about Spyder, see the Spyder web page or the Spyder
Once the installation is completed, you can search for documentation.
the Anaconda Navigator on your device and open it. The https://www.spyder-ide.org/
layout of Anaconda should resemble Figure 4. Congratula-
Other IDEs not included in Anaconda
tions, you now have everything you need to start coding in
Python (and R as well)! • PyCharm is a feature-rich IDE specifically designed for
Python and is amongst the most popular. It contains
Anaconda Navigator and IDEs
most of the important tools for programming and is
The Anaconda Navigator, shown in figure 4, is a GUI, like great for large-scale projects. Plus, it can easily be inte-
we previously mentioned. Think of this as the “menu” page grated with Anaconda. It has its own large, open source
of Anaconda, where you can easily access and launch dif- community. There is a free version of PyCharm, but the
ferent IDEs without needing to type commands in a termi- full professional version is paid.
nal window. There are many different IDEs specially de- https://www.jetbrains.com/pycharm/features/
signed for Python programming and the following ones are • VS Code is another feature-rich IDE run by Microsoft
automatically installed with Anaconda. To access an IDE, that is compatible with almost every programming lan-
click on its icon in the Navigator Home tab. guage. It is also free! The downside is that it is not
Python-specific, meaning a plugin is required to run

The Quantitative Methods for Psychology


2 S5
¦ 2020 Vol. 16 no. 5

Figure 2 Windows Installation and Setup.

(a) Welcome Screen (b) Read/accept license agrement (c) Installation type

(d) Choosing location for installation (e) Advanced installation options (f) Finish installation and close wizard

Python, but it can be linked to Anaconda.


Getting Started with Programming
https://code.visualstudio.com/docs/languages/python
• Eclipse is probably the most popular IDE in the world As previously mentioned, there are many environments
as it is used for Java programming. It is free but re- that can be used to program in Python. That being said, all
quires a plugin to be compatible with Python. This of them share similar components, despite being displayed
would be an ideal IDE for any programmer with pre- differently. These common features are the Console and
vious experience in Java. Editor. The difference between these two are the follow-
https://marketplace.eclipse.org/content/pydev-python- ing: the editor permits you to write and save any code/-
ide-eclipse variables as a script and acts as a long-term memory. The
• ATOM is a highly customizable IDE that shines with its console is like a short-term/working memory that allows
integration of Git and Github, popular version control the output to be displayed but nothing is saved. Thus, the
tools, making it useful for collaborations. It is easy to console is used to test certain lines of code to ensure that
set up and very fast to load, but it’s also not Python- they work, such as a program to calculate reaction time.
specific, meaning it requires a Python plug-in. The editor is used to save your work in memory, such as
https://atom.io/packages/ide-python a script containing the entire code for your experimental
• Sublime Text 3 is a very simple code editor and is paradigm. In figure 5, the console and editors are rep-
lightweight (does not require a heavy download). It is resented in all three IDEs (Spyder, Jupyter Notebook, and
simple and easy to use. It is also compatible with many JupyterLab). Note that the layout differs, but in each IDE,
other programming languages. While technically not the core features remain the same. It is important to also
an IDE, it is useful for beginners and experts alike. mention that for each IDE you encounter, certain features
https://realpython.com/setting-up-sublime-text-3-for- are added, making them best suited for specific tasks. De-
full-stack-python-development/ pending on your intentions, it is worth evaluating which

The Quantitative Methods for Psychology


2
S6
¦ 2020 Vol. 16 no. 5

Figure 3 Mac Installation and Setup.

(a) Welcome Screen (b) Read/accept license agrement (c) Installation type

(d) Choosing location for installation (e) Advanced installation options (f) Finish installation and close wizard

IDE would be best suited for your current needs. “Run” to execute your code and display the output in
For simplicities’ sake, this tutorial will use Jupyter Note- the console. This should result in two things. First, your
book to demonstrate how to write your first program in console should display your code’s output. Second, a
Python! Now enough of the dry explanation, let’s get cod- new cell should appear beneath it (see Fig 9). Congrat-
ing! ulations on this first step! You are now a Python pro-
grammer and are ready to explore the new horizons
Writing Your First Program
that await you!
First off, open Jupyter Notebook through the Anaconda * Note: to access your Jupyter Notebook again or any
navigator. This should result in your default internet other .ipynb files, you must open them from the main
browser opening and the display should resemble Figure Jupyter Notebook screen (Figure 6). Simply clicking on
6 (where all of your device’s files should be available to ac- them from the desktop or other files will result in an er-
cess). Select the desired destination and follow the steps to ror message.
create your first Python script.
Next Steps
1. Select “New” and choose the “Python 3” option to open
a new Script/Notebook (see Fig. 6). Now that you have started programming, there might be
2. Once the notebook is created, in the top left corner, se- questions or projects that you encounter requiring some
lect the “Untitled” name and rename the notebook for extra help. A great resource for those situations is Stack
convenience (see Fig. 7). Overflow. This free forum for developers allows you to
3. In the first cell, enter the following lines of code exactly ask questions and get reliable help quickly. It also has
as it is shown in the editor (see Fig. 8). While writing, a large repository of previously asked questions that you
you may notice certain aspects of the code will change can navigate. Another important resource to explore is
colours. This will be elaborated further in a subsequent GitHub. This is a website for storing, sharing and hosting
tutorial. code that can be downloaded by other programmers. In
4. Once everything is properly entered in the editor, press other words, GitHub allows users to share their scripts and

The Quantitative Methods for Psychology


2 S7
¦ 2020 Vol. 16 no. 5

Figure 4 Anaconda Navigator.

quickly collaborate on projects. There are other types of re-


References
sources that a programmer in Python can access for free.
As previously mentioned, the Python community is very Coutanche, M. N., & Hallion, L. S. (2019). Machine learning
large. This results in different types of collaboration hap- for clinical psychology and clinical neuroscience.
pening virtually, such as taking on a Kaggle coding chal- Dalmaijer, E. S. (2016). Python for experimental psycholo-
lenge, or local meetups, such as the ones provided by the gists. Routledge.
University of Ottawa’s Python Club. Regardless of your Helmus, J. J., & Collis, S. M. (2016). The python arm radar
next step, the most important action to take is to practice toolkit (py-art), a library for working with weather
with patience and to dive into Python’s programming lan- radar data in the python programming language.
guage syntax. As with learning any new language, practice Journal of Open Research Software, 4.
makes perfect! To become fluent in Python, it is impor- Knorr, F. G., Marxen, M., & Petzold, J. (2019). Pyparadigm-a
tant to immerse yourself in the Python community by writ- python library to build screens in a declarative way.
ing questions online, reading blog posts, attending local Frontiers in neuroinformatics, 13, 59.
programming talks, and following online courses (Codea- Lu, Z., & Ku, Y. (2020). Neurora: A python toolbox of rep-
cademy; Udemy; Official Python Tutorial). In other words, resentational analysis from multi-modal neural data.
your next step in learning Python should be fun, interac- bioRxiv.
tive, and challenging. Saabith, A. S., Fareez, M., & Vinothraj, T. (2019). Python
current trend applications-an overview. International
Authors’ note
Journal of Advance Engineering and Research Develop-
The authors can be contacted by email at ment, 6(10).
(Damien Rolon-Mérette) [email protected], (Matt Underwood, J. J., Kirchhoff, C., Warwick, H., & Gartstein,
Ross) [email protected], (Thaddé Rolon-Mérette) M. A. (2020). Leveraging python to process cross-
[email protected], or (Kinsey Church) cultural temperament interviews: A novel platform
[email protected]. for text analysis. Journal of Cross-Cultural Psychology,
51(2), 168–181.
Van Rossum, G., & Drake Jr, F. (1995). Python tutorial (vol.
620). CWI Report CS-R9526, Amsterdam, Netherlands,
msekce. karlin. mff. cuni. cz/˜ halas/IT/tutorial. pdf.

The Quantitative Methods for Psychology


2 S8
¦ 2020 Vol. 16 no. 5

Figure 5 Basic Components of Three Different IDEs, the Console (A), Editor (B), Variable Explorer (C) and Help (E) are
displayed in each IDE they apply to.

Terminology

API : Application Programming Interface is a computing interface which defines interactions between multiple software
intermediaries.
GUI : Graphical User Interface is a form of user interface that allows users to interact with electronic devices through
graphical icons and audio indicators, such as primary notation, instead of text-based user interfaces, typed command
labels or text navigation.
IDE : An Integrated Development Environment is a software application that provides comprehensive facilities to com-
puter programmers for software development. An IDE normally consists of at least a source code editor, build automation
tools, and a debugger.
Library : Collection of packages, i.e., Numpy, Matplotlib, Seaborn and Tensorflow.
Package : Collection of modules.
Module : A set of functions, types, classes, etc. Anything ending in .py.
Console : A console (also called a “shell”) is a command line interpreter that takes input from the user and interprets it.
Cannot save or store information.

The Quantitative Methods for Psychology


2 S9
¦ 2020 Vol. 16 no. 5

Figure 6 Opening a New Notebook.

Figure 7 Naming Your File.

(b)
(a)

Editor : A code editor is a tool that is used to write and edit code. It will save and store information as scripts. When
running its code, the output is usually displayed in the console.

Citation

Rolon-Mérette, D., Ross, M., Rolon-Mérette, T., & Church, K. (2020). Introduction to Anaconda and Python: Installation and
setup. The Quantitative Methods for Psychology, 16(5), S3–S11. doi:10.20982/tqmp.16.5.S003

Copyright © 2020, Rolon-Mérette, Ross, Rolon-Mérette, and Church. This is an open-access article distributed under the terms of the Creative Commons
Attribution License (CC BY). The use, distribution or reproduction in other forums is permitted, provided the original author(s) or licensor are credited
and that the original publication in this journal is cited, in accordance with accepted academic practice. No use, distribution or reproduction is
permitted which does not comply with these terms.

Received: 11/08/2020 ∼ Accepted: 23/09/2020

Figure 8 Writing Your Code.

The Quantitative Methods for Psychology


2 S10
¦ 2020 Vol. 16 no. 5

Figure 9 Running Your Code.

The Quantitative Methods for Psychology


2
S11

You might also like